Class: Reorm::ExclusionValidator

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

Instance Attribute Summary

Attributes inherited from Validator

#field, #message

Instance Method Summary collapse

Constructor Details

#initialize(values, *field) ⇒ ExclusionValidator

Returns a new instance of ExclusionValidator.



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

def initialize(values, *field)
  super("is set to an unpermitted value.", *field)
  @values = [].concat(values)
end

Instance Method Details

#validate(object) ⇒ Object



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

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