class HashValidator::Validator::RegexpValidator

Public Class Methods

new() click to toggle source
Calls superclass method HashValidator::Validator::Base::new
# File lib/hash_validator/validators/regex_validator.rb, line 2
def initialize
  super('_regex')  # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator)
end

Public Instance Methods

presence_error_message() click to toggle source
# File lib/hash_validator/validators/regex_validator.rb, line 10
def presence_error_message
  'does not match regular expression'
end
should_validate?(rhs) click to toggle source
# File lib/hash_validator/validators/regex_validator.rb, line 6
def should_validate?(rhs)
  rhs.is_a?(Regexp)
end
validate(key, value, regexp, errors) click to toggle source
# File lib/hash_validator/validators/regex_validator.rb, line 14
def validate(key, value, regexp, errors)
  unless regexp.match(value.to_s)
    errors[key] = presence_error_message
  end
end