Class: Respect::MinLengthValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/respect/min_length_validator.rb

Instance Method Summary (collapse)

Methods inherited from Validator

constraint_name, #to_h

Constructor Details

- (MinLengthValidator) initialize(min_length)

A new instance of MinLengthValidator



3
4
5
# File 'lib/respect/min_length_validator.rb', line 3

def initialize(min_length)
  @min_length = min_length
end

Instance Method Details

- (Object) validate(value)



7
8
9
10
11
12
# File 'lib/respect/min_length_validator.rb', line 7

def validate(value)
  unless value.length >= @min_length
    raise ValidationError,
          "#{value.inspect} must be at least #@min_length long but is #{value.length}"
  end
end