class ActiveModel::Validations::SubdomainValidator

Public Instance Methods

reserved?(subdomain) click to toggle source
# File lib/validators/validates_subdomain.rb, line 16
def reserved?(subdomain)
  ::Validators::ReservedSubdomains.reserved?(subdomain, options[:in])
end
validate_each(record, attribute, value) click to toggle source
# File lib/validators/validates_subdomain.rb, line 6
def validate_each(record, attribute, value)
  return if value.blank? && options[:allow_blank]
  return if value.nil? && options[:allow_nil]

  value = value.to_s

  validate_reserved_subdomain(record, attribute, value)
  validate_format(record, attribute, value)
end
validate_format(record, attribute, value) click to toggle source
# File lib/validators/validates_subdomain.rb, line 32
def validate_format(record, attribute, value)
  return if Validators::Hostname.valid_label?(value)

  record.errors.add(
    attribute,
    :"invalid_#{options[:error_name]}",
    message: options[:message],
    value: value
  )
end
validate_reserved_subdomain(record, attribute, value) click to toggle source
# File lib/validators/validates_subdomain.rb, line 20
def validate_reserved_subdomain(record, attribute, value)
  return unless options.fetch(:reserved, true)
  return unless reserved?(value)

  record.errors.add(
    attribute,
    :"reserved_#{options[:error_name]}",
    message: options[:message],
    value: value
  )
end