Class: Reorm::ExclusionValidator
- Defined in:
- lib/reorm/validators/exclusion_validator.rb
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(values, *field) ⇒ ExclusionValidator
constructor
A new instance of ExclusionValidator.
- #validate(object) ⇒ Object
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, ) end end |