Class: DomainnameValidator
- Inherits:
-
HostnameValidator
- Object
- ActiveModel::EachValidator
- HostnameValidator
- DomainnameValidator
- Defined in:
- lib/valid_hostname/domainname_validator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ DomainnameValidator
constructor
A new instance of DomainnameValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ DomainnameValidator
Returns a new instance of DomainnameValidator.
6 7 8 9 |
# File 'lib/valid_hostname/domainname_validator.rb', line 6 def initialize() super({ require_valid_tld: true, allow_numeric_hostname: true }.merge()) end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/valid_hostname/domainname_validator.rb', line 11 def validate_each(record, attribute, value) super return unless value.is_a? String return if [:allow_numeric_hostname] != true labels = value.split '.' is_numeric_only = labels[0] =~ /\A\d+\z/ add_error record, attribute, :single_numeric_hostname_label if is_numeric_only && labels.size == 1 end |