Sha256: d6b249fef91cd58e2b0f641201c3665813cde185514918c892783d7fc905f715

Contents?: true

Size: 594 Bytes

Versions: 6

Compression:

Stored size: 594 Bytes

Contents

class HashValidator::Validator::RegexpValidator < HashValidator::Validator::Base
  def initialize
    super('_regex')  # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator)
  end

  def should_validate?(rhs)
    rhs.is_a?(Regexp)
  end

  def presence_error_message
    'does not match regular expression'
  end

  def validate(key, value, regexp, errors)
    unless regexp.match(value.to_s)
      errors[key] = presence_error_message
    end
  end
end

HashValidator.append_validator(HashValidator::Validator::RegexpValidator.new)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hash_validator-1.1.1 lib/hash_validator/validators/regex_validator.rb
hash_validator-1.1.0 lib/hash_validator/validators/regex_validator.rb
hash_validator-1.0.0 lib/hash_validator/validators/regex_validator.rb
hash_validator-0.8.0 lib/hash_validator/validators/regex_validator.rb
hash_validator-0.7.1 lib/hash_validator/validators/regex_validator.rb
hash_validator-0.7.0 lib/hash_validator/validators/regex_validator.rb