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

validation for array in params #333

Merged
merged 2 commits into from Feb 12, 2013
Merged

Conversation

flyerhzm
Copy link
Contributor

validation support for array in params, like

{
  name: "Post",
  tags: [{name: "ruby"}, {name: "python"}]
}
params do
  group :tags do
    requires :name
  end
end

@dblock
Copy link
Member

dblock commented Feb 12, 2013

Two things:

  1. Can you please update CHANGELOG.
  2. Do you think this can be generalized into checking for Enumerable vs. just Array?

@flyerhzm
Copy link
Contributor Author

  1. I have updated CHANGELOG.
  2. I don't think it needs to use Enumerable, as params could only be Array, not Enumerable, if I don't misunderstand anything.

@attrs.each do |attr_name|
if @required || params.has_key?(attr_name)
validate_param!(attr_name, params)
(params.is_a?(Array) ? params : [params]).each do |resource_params|
Copy link
Member

Choose a reason for hiding this comment

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

Minor note, there's a more elegant way to write this, I think you can just do Array(params).each, it will make an array of params if params is not an array.

@dblock
Copy link
Member

dblock commented Feb 12, 2013

Thanks, merging.

dblock added a commit that referenced this pull request Feb 12, 2013
validation for array in params
@dblock dblock merged commit 87f7a7f into ruby-grape:master Feb 12, 2013
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.

None yet

2 participants