Class: EacRailsUtils::UriValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/eac_rails_utils/uri_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



7
8
9
10
11
12
# File 'app/validators/eac_rails_utils/uri_validator.rb', line 7

def validate_each(record, attribute, value)
  r = ::Addressable::URI.parse(value)
  raise ::Addressable::URI::InvalidURIError, 'No scheme' if r.scheme.blank?
rescue ::Addressable::URI::InvalidURIError => e
  record.errors.add(attribute, options[:message] || e.message)
end