Class: HashValidator::Validator::UrlValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/hash_validator/validators/url_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#should_validate?

Constructor Details

#initializeUrlValidator

Returns a new instance of UrlValidator.



4
5
6
# File 'lib/hash_validator/validators/url_validator.rb', line 4

def initialize
  super('url')  # The name of the validator
end

Instance Method Details

#presence_error_messageObject



8
9
10
# File 'lib/hash_validator/validators/url_validator.rb', line 8

def presence_error_message
  'is not a valid URL'
end

#validate(key, value, _validations, errors) ⇒ Object



12
13
14
15
16
# File 'lib/hash_validator/validators/url_validator.rb', line 12

def validate(key, value, _validations, errors)
  unless value.is_a?(String) && valid_url?(value)
    errors[key] = presence_error_message
  end
end