Class: ATDIS::Validators::HttpUrlValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/atdis/validators.rb', line 28

def validate_each(record, attribute, value)
  raw_value = record.send("#{attribute}_before_type_cast")
  return unless raw_value.present? && !value.is_a?(URI::HTTP) && !value.is_a?(URI::HTTPS)

  message = "is not a valid URL"
  message = ErrorMessage[message, options[:spec_section]] if options[:spec_section]
  record.errors.add(attribute, message)
end