-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Bugfix for issue 699 - scoped mutual methods #774
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
Bugfix for issue 699 - scoped mutual methods #774
Conversation
If you need I will add some info to readme as well. |
I've added examples to readme. |
great work cracking the nut :) After a couple of passes it looks solid to me. I'd just change SeveralParamsBase to MultipleParamsBase. Feel a little funny about two base classes, but I can't think of another way really |
Hi Oliver! |
@@ -1,6 +1,7 @@ | |||
0.9.1 (Next) | |||
============ | |||
|
|||
* [#774](https://github.com/intridea/grape/pull/774): Change `mutually_exclusive`, `exactly_one_of`, `at_least_one_of` to work inside any kind of group: `requires` or `optional`, `Hash` or `Array` - [@ShPakvel](https://github.com/ShPakvel). |
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.
Nitpick: maybe "Enabled mutually_exclusive
, ..." or "Extended ..." or "Allowed ...". It's really either a fix or a new feature.
This is perfect, read the code, great job. Can you squash and I'll merge? Thanks. |
def keys_in_common | ||
(attrs.map(&:to_s) & params.stringify_keys.keys).map(&:to_s) | ||
scoped_params.each do |resource_params| | ||
return true if keys_in_common(resource_params).length == 0 |
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.
Maybe .any?
works too.
@dblock Great catch regarding |
d833864
to
732d81e
Compare
|
||
def all_keys | ||
attrs.map(&:to_s) | ||
scoped_params.any? { |resource_params| keys_in_common(resource_params).length < 1 } |
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 can be .none?
I believe.
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.
Actually here it is not possible. But I can change .length < 1
to .empty?
What do you think?
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 gush, I misunderstood you )) you wanted the same think as me, just another method for this. )) Am I right?
Rebase too. |
…in group change mutually_exclusive to work in scope change exactly_one_of to work in scope change at_least_one_of to work in scope all of those methods changed to work for Hash and Array all of those methods changed to work for requires and optional scope add and change specs
732d81e
to
f2d586e
Compare
Check it one more time please. I think this is what you wanted. 😉 |
@dblock do you need any other changes? |
This is great, merging. |
…ethods Bugfix for issue 699 - scoped mutual methods
@dblock I wonder if it is possible to shortly release new gem version with this and other changes/features? |
Yes. I'll do it soonish. |
Hi guys.
I think I figured out how to solve #699 .
Here are changes I've made:
mutually_exclusive
to work in scopeexactly_one_of
to work in scopeat_least_one_of
to work in scopeHash
andArray
requires
andoptional
scopeThank you for the grape!
Pavel