Class: Grape::Validations::Validators::RegexpValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/validations/validators/regexp_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

default_message_key, #fail_fast?, inherited, new, #validate, #validate!

Constructor Details

#initialize(attrs, options, required, scope, opts) ⇒ RegexpValidator

Returns a new instance of RegexpValidator.



9
10
11
12
# File 'lib/grape/validations/validators/regexp_validator.rb', line 9

def initialize(attrs, options, required, scope, opts)
  super
  @value = option_value
end

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/grape/validations/validators/regexp_validator.rb', line 14

def validate_param!(attr_name, params)
  return unless hash_like?(params) && params.key?(attr_name)

  return if Array.wrap(params[attr_name]).all? { |param| param.nil? || scrub(param.to_s).match?(@value) }

  validation_error!(attr_name)
end