Parent

ActiveModel::Validations::DomainValidator

Public Class Methods

new(options) click to toggle source
# File lib/active_model/validations/domain_validator.rb, line 4
def initialize(options)
  options[:length]       ||= ::Validator::Domain::LENGTH
  options[:label_length] ||= ::Validator::Domain::LABEL_LENGTH

  super(options)
end

Public Instance Methods

validate_each(record, attr_name, value) click to toggle source
# File lib/active_model/validations/domain_validator.rb, line 11
def validate_each(record, attr_name, value)
  # do not validate if value is empty
  return if value.nil?

  @validator = ::Validator::Domain.new(value)

  # max domain length
  unless @validator.valid_by_length?(options[:length])
    record.errors.add(attr_name, :'domain.length', options)
  end

  # label is limited to between 1 and 63 octets
  unless @validator.valid_by_label_length?(options[:label_length])
    record.errors.add(attr_name, :'domain.label_length', options)
  end

  # skip proceeding validation if errors
  return unless record.errors.blank?

  unless @validator.valid_by_regexp?
    record.errors.add(attr_name, :'domain.invalid', options)
    return
  end

  # if check_tld = true - check if TLD exists
  if options[:check_tld] != false
    tld = value.split('.').last.upcase
    unless ::Validator::Domain::Tld.exists?(tld)
      record.errors.add(attr_name, :'domain.unknown_tld', options)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.