Class: Grape::Validations::RegexpValidator

Inherits:
Base
  • Object
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, #fail_fast?, inherited, #initialize, #message, #options_key?, #validate, #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
# File 'lib/grape/validations/validators/regexp.rb', line 4

def validate_param!(attr_name, params)
  return unless params.respond_to?(:key?) && params.key?(attr_name)
  return if Array.wrap(params[attr_name]).all? { |param| param.nil? || (param.to_s =~ (options_key?(:value) ? @option[:value] : @option)) }
  raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:regexp)
end