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