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
14 15 16 |
# File 'lib/validators/validates_subdomain.rb', line 14 def reserved?(subdomain) ::Validators::ReservedSubdomains.reserved?(subdomain, [:in]) end |
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 12 |
# 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] validate_reserved_subdomain(record, attribute, value) validate_format(record, attribute, value) end |
#validate_format(record, attribute, value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/validators/validates_subdomain.rb', line 30 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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/validators/validates_subdomain.rb', line 18 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 |