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