Skip to content

Fix: allow usage of attributes with name 'key' if Hash objects are used #111

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

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

croeck
Copy link
Contributor

@croeck croeck commented Mar 10, 2015

Fix now is checking the method arity in the delegate_attribute method. With this change the key attribute will be fetched and instead of the key method (with arity 1) being invoked.
The fix includes a spec that demonstrates the issue and fails without the changes.

@croeck croeck force-pushed the using-hash-object-arity branch from ee7ee3e to a63875f Compare March 10, 2015 11:00
@@ -557,7 +557,7 @@ def delegate_attribute(attribute)
if respond_to?(name, true)
send(name)
else
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, I think this can be collapsed into an elsif.

@croeck croeck force-pushed the using-hash-object-arity branch from a63875f to ee3b6cb Compare March 10, 2015 11:01
@@ -557,7 +557,7 @@ def delegate_attribute(attribute)
if respond_to?(name, true)
send(name)
else
if object.respond_to?(name, true)
if object.respond_to?(name, true) && object.method(name).arity == 0
Copy link
Member

Choose a reason for hiding this comment

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

This worries me. If there's a special case with Hash I would just check for that.

@croeck
Copy link
Contributor Author

croeck commented Mar 10, 2015

Alright, I'll update the pull request in a few minutes...

@croeck croeck force-pushed the using-hash-object-arity branch from ee3b6cb to e1815d7 Compare March 10, 2015 11:15
@croeck
Copy link
Contributor Author

croeck commented Mar 10, 2015

Pull is updated, arity check was replaced with object.is_a? Hash and if..else was combined to one large if..elsif..else statement

@dblock
Copy link
Member

dblock commented Mar 10, 2015

Much better. Merging.

dblock added a commit that referenced this pull request Mar 10, 2015
Fix: allow usage of attributes with name 'key' if `Hash` objects are used
@dblock dblock merged commit 7035174 into ruby-grape:master Mar 10, 2015
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