Class: Katello::Validators::KatelloURLFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
KatelloURLHelper
Defined in:
app/lib/katello/validators/katello_url_format_validator.rb

Constant Summary

Constants included from KatelloURLHelper

KatelloURLHelper::CONSTANTS_DEFINED, KatelloURLHelper::FILEPREFIX, KatelloURLHelper::PROTOCOLS

Instance Method Summary collapse

Methods included from KatelloURLHelper

#kurl_valid?

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/lib/katello/validators/katello_url_format_validator.rb', line 6

def validate_each(record, attribute, value)
  if options[:nil_allowed]
    if options[:nil_allowed].respond_to?(:call)
      return if value.nil? && options[:nil_allowed].call(record)
    else
      return if value.nil?
    end
  end

  attribute_name = options[:field_name] || attribute
  record.errors.add(attribute_name, N_("is invalid")) unless kurl_valid?(value)
end