Class: Reorm::InclusionValidator

Inherits:
Validator show all
Defined in:
lib/reorm/validators/inclusion_validator.rb

Instance Attribute Summary

Attributes inherited from Validator

#field, #message

Instance Method Summary collapse

Constructor Details

#initialize(values, *field) ⇒ InclusionValidator

Returns a new instance of InclusionValidator.



7
8
9
10
# File 'lib/reorm/validators/inclusion_validator.rb', line 7

def initialize(values, *field)
  super("is not set to one of its permitted values.", *field)
  @values = values
end

Instance Method Details

#validate(object) ⇒ Object



12
13
14
15
16
# File 'lib/reorm/validators/inclusion_validator.rb', line 12

def validate(object)
  if !@values.include?(field.value(object))
    object.errors.add(field.to_s, message)
  end
end