mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Refactor
This commit is contained in:
parent
da950f5df7
commit
a9e1414ddc
4 changed files with 3 additions and 31 deletions
|
@ -2,6 +2,6 @@ class Nameserver < ActiveRecord::Base
|
|||
belongs_to :registrar
|
||||
has_and_belongs_to_many :domains
|
||||
|
||||
validates :hostname, hostname: true
|
||||
validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true, message: :ip_invalid}
|
||||
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
||||
validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true }
|
||||
end
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
class HostnameValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if !self.class.validate_format(value)
|
||||
record.errors.add(attribute, (options[:message] || :invalid))
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
!!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
class NameserverIpValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if record.domain_
|
||||
|
||||
if !self.class.validate_format(value)
|
||||
record.errors.add(attribute, (options[:message] || :invalid))
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
!!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -55,7 +55,7 @@ en:
|
|||
hostname:
|
||||
invalid: 'Hostname is invalid'
|
||||
ip:
|
||||
ip_invalid: 'IP is invalid'
|
||||
invalid: 'IP is invalid'
|
||||
|
||||
|
||||
errors:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue