Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP to use the default option as in catmandu #333 #356

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TobiasNx
Copy link
Collaborator

@TobiasNx TobiasNx commented Jun 6, 2024

No description provided.

@@ -530,8 +531,11 @@ public void apply(final Metafix metafix, final Record record, final List<String>
if (c != null) {
c.accept(oldValue);
}

elsif (defaultOption != null){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch will not be reached when print_unknown="true".


elsif (defaultOption != null){
return defaultOption;
}
return defaultValue != null ? defaultValue : delete ? null : oldValue;
Copy link
Member

@blackwinter blackwinter Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return defaultValue != null ? defaultValue : delete ? null : oldValue;
return defaultOption != null ? defaultOption : defaultValue != null ? defaultValue : delete ? null : oldValue;

As previously suggested, this would be even better though (at the top of the method):

final String defaultValue = options.getOrDefault(Maps.DEFAULT_MAP_KEY, map.get(Maps.DEFAULT_MAP_KEY));

It would allow you to specify/override the default value per lookup call in addition to per map. The next step would then be to decide whether we want to keep supporting the Metamorph syntax (__default) or switch to the Catmandu syntax (default). Or even support both (which seems a little messy, though).

return defaultValue != null ? defaultValue : delete ? null : oldValue;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add/remove empty lines in existing code ;)

@TobiasNx
Copy link
Collaborator Author

@blackwinter could you help me how I would continue here? I would suggest to drop the _default version of metamorph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants