Class: Respect::MaxLengthValidator
- Inherits:
-
Validator
- Object
- Validator
- Respect::MaxLengthValidator
- Defined in:
- lib/respect/max_length_validator.rb
Instance Method Summary (collapse)
-
- (MaxLengthValidator) initialize(max_length)
constructor
A new instance of MaxLengthValidator.
- - (Object) validate(value)
Methods inherited from Validator
Constructor Details
- (MaxLengthValidator) initialize(max_length)
A new instance of MaxLengthValidator
3 4 5 |
# File 'lib/respect/max_length_validator.rb', line 3 def initialize(max_length) @max_length = max_length end |
Instance Method Details
- (Object) validate(value)
7 8 9 10 11 12 |
# File 'lib/respect/max_length_validator.rb', line 7 def validate(value) unless value.length <= @max_length raise ValidationError, "#{value.inspect} must be at most #@max_length long but is #{value.length}" end end |