Skip to content
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

Merged

Conversation

ochagata
Copy link
Contributor

@ochagata ochagata commented Jan 5, 2016

It will now expect any amount of inputs and will iterate on the input

@ochagata
Copy link
Contributor Author

ochagata commented Jan 5, 2016

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)
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

@dblock
Copy link
Member

dblock commented Jan 6, 2016

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.

@ochagata ochagata force-pushed the feature/allow_chained_input_to_given branch from c8be0b0 to 45d89ad Compare January 6, 2016 17:55
@ochagata
Copy link
Contributor Author

ochagata commented Jan 6, 2016

@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)
Copy link
Member

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.

@dblock
Copy link
Member

dblock commented Jan 6, 2016

I just have two small nitpicks on CHANGELOG and stuff ... sorry to be a pain.

@ochagata ochagata force-pushed the feature/allow_chained_input_to_given branch from 16b0124 to bafeaf9 Compare January 6, 2016 20:04
@ochagata
Copy link
Contributor Author

ochagata commented Jan 6, 2016

All notes addressed and changes made

dblock added a commit that referenced this pull request Jan 6, 2016
@dblock dblock merged commit 87cd364 into ruby-grape:master Jan 6, 2016
@dblock
Copy link
Member

dblock commented Jan 6, 2016

Merged, 👍

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.

3 participants