-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Allow deep indifferent access on Hanami::Utils::Attributes #137
Conversation
@@ -51,6 +51,14 @@ def to_h | |||
attributes.get('23').must_equal 'foo' | |||
end | |||
|
|||
it 'allows deep indifferent access' do | |||
attributes = Hanami::Utils::Attributes.new(foo: {baz: 'bar'}) | |||
attributes.get(:foo).get(:baz).must_equal 'bar' |
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.
good one, can we test against the nested string syntax instead? eg: params.get('address.street')
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.
Oh yeah, I forgot to test that one. New commit coming up.
How about this? |
looks good, the test fails for other unrelated reason. Would you be able to have a look at that too? |
break unless value | ||
|
||
value = value[key] | ||
end |
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.
What do you think, maybe is better to get only last key from split
instead unnecessary enumeration? I. e.:
value = @attributes
key = attribute.to_s.split(?.).last
value = value[key] if value
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.
We wouldn't be able to cover deep access with that, like for example:
attributes = Hanami::Utils::Attributes.new({address: {street: 'Street', city: 'City'}})
attributes.get("address.street")
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.
yep, you're right!
Thanks for explanation! 👍
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.
👍
@joneslee85: Can't reproduce the error on my local, but sure I'll also take a look at it. |
99f6325
to
2bc5ce3
Compare
I squashed my commits and Travis already passed. Maybe a brittle test for file permissions? |
Thanks for the merge! |
Address hanami/controller#70 by making
Hanami::Utils::Attribute#get
returnHanami::Utils::Attributes
for hash-like attribute values.