Class: Grape::Validations::RegexpValidator

Inherits:
Base show all
Defined in:
lib/grape/validations/validators/regexp.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

convert_to_short_name, inherited, #initialize, #validate!

Constructor Details

This class inherits a constructor from Grape::Validations::Base

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object


4
5
6
7
8
9
# File 'lib/grape/validations/validators/regexp.rb', line 4

def validate_param!(attr_name, params)
  if params.key?(attr_name) &&
     (params[attr_name].nil? || !(params[attr_name].to_s =~ @option))
    fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message_key: :regexp
  end
end