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

Allow to use regexp validator with arrays #1503

Merged
merged 3 commits into from
Oct 7, 2016

Conversation

akoltun
Copy link
Contributor

@akoltun akoltun commented Oct 6, 2016

Ex. this will work

params do
  requires :names, type: Array[String], regexp: /^[a-z]+$/
end

@@ -2,7 +2,8 @@ module Grape
module Validations
class RegexpValidator < Base
def validate_param!(attr_name, params)
return unless params.key?(attr_name) && !params[attr_name].nil? && !(params[attr_name].to_s =~ (options_key?(:value) ? @option[:value] : @option))
return unless params.respond_to?(:has_key?) && params.has_key?(attr_name)
Copy link
Contributor

@namusyaka namusyaka Oct 6, 2016

Choose a reason for hiding this comment

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

Rubocop said, please use key? instead of has_key.

@namusyaka
Copy link
Contributor

@akoltun Thanks for your pull request. This change looks like reasonable.
Please check my comment out.

@dblock
Copy link
Member

dblock commented Oct 7, 2016

This looks good, merging.

@dblock dblock merged commit 2d34f29 into ruby-grape:master Oct 7, 2016
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

3 participants