Class: Respect::MatchValidator

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

Instance Method Summary (collapse)

Methods inherited from Validator

constraint_name, #to_h

Constructor Details

- (MatchValidator) initialize(pattern)

A new instance of MatchValidator



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

def initialize(pattern)
  @pattern = pattern
end

Instance Method Details

- (Object) validate(value)



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

def validate(value)
  unless value =~ @pattern
    raise ValidationError, "#{value.inspect} does not match #{@pattern.inspect}"
  end
end