Sha256: c34a98f2ceec59e505d506c4539f3f39cd2ddc5d81628f9e19a0984529af1517

Contents?: true

Size: 686 Bytes

Versions: 18

Compression:

Stored size: 686 Bytes

Contents

class SubdomainValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    return unless value.present?
    reserved_names = %w(www ftp mail pop smtp admin ssl sftp)
    reserved_names = options[:reserved] if options[:reserved]

    if reserved_names.include?(value)
      object.errors[attribute] << 'cannot be a reserved name'
    end

    object.errors[attribute] << 'must have between 3 and 63 letters' unless (3..63) === value.length
    object.errors[attribute] << 'cannot start or end with a hyphen' unless value =~ /^[^-].*[^-]$/i
    object.errors[attribute] << 'must be alphanumeric; A-Z, 0-9 or hyphen' unless value =~ /^[a-z0-9\-]*$/i
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
trax_model-0.1.0 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.99 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.98 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.97 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.96 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.95 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.93 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.92 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.91 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.9 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.8 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.7 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.6 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.5 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.4 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.3 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.2 lib/trax/validators/subdomain_validator.rb
trax_model-0.0.1 lib/trax/validators/subdomain_validator.rb