-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Conversation
6b01722
to
18b78f0
Compare
@@ -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){ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
|
There was a problem hiding this comment.
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 ;)
1e4938e
to
a505fc5
Compare
@blackwinter could you help me how I would continue here? I would suggest to drop the |
No description provided.