Class: Respect::EqualToValidator

Inherits:
Validator show all
Defined in:
lib/respect/equal_to_validator.rb

Instance Method Summary (collapse)

Methods inherited from Validator

constraint_name, #to_h

Constructor Details

- (EqualToValidator) initialize(expected)

A new instance of EqualToValidator



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

- (Object) validate(value)



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

def validate(value)
  unless value == @expected
    raise ValidationError,
          "wrong value: `#{value}':#{value.class} instead of `#@expected':#{@expected.class}"
  end
end