-
Notifications
You must be signed in to change notification settings - Fork 268
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
Fix template expand level 2 hash support for non-string objects #499
Conversation
if value.kind_of?(Array) | ||
value.map! { |val| normalize_value(val) } | ||
if value.respond_to?(:to_ary) | ||
value.to_ary.map! { |val| normalize_value(val) } |
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.
Here I just simplified a bit the code, treating all array-like object in the same place instead of having the first like (900) to convert first.
elsif value.kind_of?(Hash) | ||
value = value.inject({}) { |acc, (k, v)| | ||
acc[normalize_value(k)] = normalize_value(v) | ||
acc | ||
} | ||
else | ||
value = value.to_s if !value.kind_of?(String) |
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.
And this is the fix basically, restoring the to_s
behavior which I accidentally changed for to_str
when I modified this method to make it recursive.
@@ -209,7 +209,7 @@ | |||
:path => "/foo/bar", | |||
:semi => ";", | |||
:list => %w(red green blue), | |||
:keys => {"semi" => ';', "dot" => '.', "comma" => ','} | |||
:keys => {"semi" => ';', "dot" => '.', :comma => ','} |
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.
I noticed this specs are weird to write (you need to write a big array of expected outputs in different orders, probably legacy ruby 1.8 stuff when hash where unordered). So I just modified existing specs here to make it simple.
I'll probably make another PR to simplify those specs after I confirm it was only for ruby 1.8.
@@ -404,7 +404,7 @@ | |||
{ | |||
:var => "value", | |||
:semi => ";", | |||
:year => %w(1965 2000 2012), | |||
:year => [1965, 2000, 2012], |
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.
And this was a good existing example to test integers too 👍
Here's the fix for #498