-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changed the input of given
#1237
Changed the input of given
#1237
Conversation
In response to #1231 |
def given(*attrs, &block) | ||
attrs.each do |attr| | ||
fail Grape::Exceptions::UnknownParameter.new(attr) unless declared_param?(attr) | ||
new_lateral_scope(dependent_on: attr, &block) |
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.
Hey Ozzy! This is a good start. But I think this is going to open up one scope per each attribute listed and repeat the nested definitions each time. I haven't tested it, so this is a guess, but I believe the behavior it will actually cause is more like if you'd written:
given :a do
requires :c
end
given :b do
requires :c
end
Instead, I think you either want to update how dependent_on
is parsed to allow it to be an array, or create these scopes such that they're nested. That is, emulate:
given :a do
given :b do
requires :c
end
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.
@rnubel
I made a change to fix this. Now the behavior is this:
given :a, :b
will now only do the validation if both :a
and :b
are both given, which would mimic the nested structure as well
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, looks good to me now.
This looks great. You might want to split up the specs a bit, one for a single parameter, one for multiple. Please squash the commits and update CHANGELOG. |
c8be0b0
to
45d89ad
Compare
@dblock should be good to go once travis finishes |
@@ -5,6 +5,7 @@ | |||
|
|||
* [#1227](/~https://github.com/ruby-grape/grape/pull/1227): Store `message_key` on Grape::Exceptions::Validation - [@stjhimy](/~https://github.com/sthimy). | |||
* [#1232](/~https://github.com/ruby-grape/grape/pull/1232): Helpers are now available inside `rescue_from` - [@namusyaka](/~https://github.com/namusyaka). | |||
* [#1237](/~https://github.com/ruby-grape/grape/pull/1237): Given now takes multiple inputs and behaves as though the scopes were nested in the inputted order - [@ochagata](/~https://github.com/ochagata) |
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.
Given is a keyword, so maybe "Allow multiple parameters in given
, which behaves as if the scopes were nested in the inputted order".
Missing a trailing period, please.
I just have two small nitpicks on CHANGELOG and stuff ... sorry to be a pain. |
…s which will create nested scopes.
16b0124
to
bafeaf9
Compare
All notes addressed and changes made |
…_given Changed the input of `given`
Merged, 👍 |
It will now expect any amount of inputs and will iterate on the input