Class: Reins::Model::Validations::LengthValidator
- Defined in:
- lib/reins/model/validations.rb
Instance Method Summary collapse
Methods inherited from Validator
Constructor Details
This class inherits a constructor from Reins::Model::Validations::Validator
Instance Method Details
#validate(record, errors) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/reins/model/validations.rb', line 77 def validate(record, errors) value = value_for(record) return if value.nil? length = value.to_s.length errors.add(@attr, "is the wrong length") if @options[:in] && !@options[:in].include?(length) errors.add(@attr, "is too short") if @options[:minimum] && length < @options[:minimum] errors.add(@attr, "is too long") if @options[:maximum] && length > @options[:maximum] end |