Class: Reorm::MaximumLengthValidator
- Defined in:
- lib/reorm/validators/maximum_length_validator.rb
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(length, *field) ⇒ MaximumLengthValidator
constructor
A new instance of MaximumLengthValidator.
- #validate(object) ⇒ Object
Constructor Details
#initialize(length, *field) ⇒ MaximumLengthValidator
Returns a new instance of MaximumLengthValidator.
7 8 9 10 |
# File 'lib/reorm/validators/maximum_length_validator.rb', line 7 def initialize(length, *field) super("is too long (maximum length is #{length} characters).", *field) @length = length end |
Instance Method Details
#validate(object) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/reorm/validators/maximum_length_validator.rb', line 12 def validate(object) value = field.value(object) if value && value.to_s.length > @length object.errors.add field.to_s, end end |