-
Notifications
You must be signed in to change notification settings - Fork 17
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
Nested params and json/yaml files #50
Conversation
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 feature is very cool! Particularly how you can mix/match loading of json and defining locally.
My main comment is a suggestion to use an iterative rather than recursive schemes (I was always taught to use iterative over the latter when possible!).
|
||
} | ||
|
||
protected void evaluateNestedClosures(Map<String, Object> map) { |
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 could also be written iteratively:
protected void evaluateNestedClosures(Map<String, Object> map) {
Queue< Map<String, Object> > queue = new LinkedList< Map<String, Object> >();
queue.add(map);
while (queue.size() > 0) {
Map<String, Object> item = queue.remove();
for (String key : item.keySet()) {
Object value = item.get(key);
if (!(value instanceof Closure)) continue;
Map<String, Object> nestedMap = createNestedMap();
Closure closure = (Closure) value;
closure.setDelegate(nestedMap);
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
closure.call();
item.put(key, nestedMap);
queue.add(nestedMap); // Instead of recursion
}
}
}
Great idea, thanks Aaron! 👍 |
Fixes #15