Class: Perfectline::ValidatesUrl::Rails3::UrlValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validates_url.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ UrlValidator

Returns a new instance of UrlValidator.



53
54
55
56
57
# File 'lib/validates_url.rb', line 53

def initialize(options)
  options.reverse_merge!(:schemes => %w(http https))
  options.reverse_merge!(:message => "is not a valid URL")
  super(options)
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



59
60
61
62
63
# File 'lib/validates_url.rb', line 59

def validate_each(record, attribute, value)
  unless Perfectline::ValidatesUrl::Validator.valid_url?(value, options.fetch(:schemes))
    record.errors.add(attribute, options.fetch(:message), :value => value)
  end
end