Class: Grape::Validations::ValuesValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/grape/validations/values.rb

Instance Attribute Summary

Attributes inherited from Validator

#attrs

Instance Method Summary collapse

Methods inherited from Validator

inherited, #validate!

Constructor Details

#initialize(attrs, options, required, scope) ⇒ ValuesValidator

Returns a new instance of ValuesValidator.


4
5
6
7
# File 'lib/grape/validations/values.rb', line 4

def initialize(attrs, options, required, scope)
  @values = options
  super
end

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object


9
10
11
12
13
# File 'lib/grape/validations/values.rb', line 9

def validate_param!(attr_name, params)
  if params[attr_name] && !@values.include?(params[attr_name])
    raise Grape::Exceptions::Validation, param: @scope.full_name(attr_name), message_key: :values
  end
end