Class: UrlValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/workarea/validators/url_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_url?(value) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/workarea/validators/url_validator.rb', line 2

def self.valid_url?(value)
  !!URI.regexp(%w(http https)).match(value.to_s)
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
# File 'lib/workarea/validators/url_validator.rb', line 6

def validate_each(record, attribute, value)
  unless self.class.valid_url?(value)
    record.errors[attribute] << (options[:message] || "must be a valid")
  end
end