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[attribute_name] << N_("is invalid") unless kurl_valid?(value)
end