Class: ActiveModel::Validations::SubdomainValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::SubdomainValidator
- Defined in:
- lib/validators/validates_subdomain.rb
Direct Known Subclasses
Instance Method Summary collapse
- #reserved?(subdomain) ⇒ Boolean
- #validate_each(record, attribute, value) ⇒ Object
- #validate_format(record, attribute, value) ⇒ Object
- #validate_reserved_subdomain(record, attribute, value) ⇒ Object
Instance Method Details
#reserved?(subdomain) ⇒ Boolean
16 17 18 |
# File 'lib/validators/validates_subdomain.rb', line 16 def reserved?(subdomain) ::Validators::ReservedSubdomains.reserved?(subdomain, [:in]) end |
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/validators/validates_subdomain.rb', line 6 def validate_each(record, attribute, value) return if value.blank? && [:allow_blank] return if value.nil? && [:allow_nil] value = value.to_s validate_reserved_subdomain(record, attribute, value) validate_format(record, attribute, value) end |
#validate_format(record, attribute, value) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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_#{[:error_name]}", message: [:message], value: value ) end |
#validate_reserved_subdomain(record, attribute, value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/validators/validates_subdomain.rb', line 20 def validate_reserved_subdomain(record, attribute, value) return unless .fetch(:reserved, true) return unless reserved?(value) record.errors.add( attribute, :"reserved_#{[:error_name]}", message: [:message], value: value ) end |