refactored after review

This commit is contained in:
dinsmol 2021-09-17 11:05:25 +03:00
parent 170652679d
commit e1e8979736

View file

@ -160,10 +160,7 @@ class Registrar < ApplicationRecord
next next
end end
new_nameserver = Nameserver.new create_nameserver(origin.domain, new_attributes)
new_nameserver.domain = origin.domain
new_nameserver.attributes = new_attributes
new_nameserver.save!
domain_scope.delete_if { |i| i == idn || i == puny } domain_scope.delete_if { |i| i == idn || i == puny }
domain_list << idn domain_list << idn
@ -184,7 +181,15 @@ class Registrar < ApplicationRecord
return if domains.empty? return if domains.empty?
domain_scope.each do |domain_name| domain_list_processing(domain_scope, new_attributes, domain_list, failed_list)
self.domains.where(name: domain_list).find_each(&:update_whois_record) if domain_list.any?
[domain_list.uniq.sort, (domain_scope + failed_list).uniq.sort]
end
end
def domain_list_processing(domains, new_attributes, domain_list, failed_list)
domains.each do |domain_name|
domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name)
if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain)
@ -192,18 +197,18 @@ class Registrar < ApplicationRecord
next next
end end
new_nameserver = Nameserver.new create_nameserver(domain, new_attributes)
new_nameserver.domain = domain
new_nameserver.attributes = new_attributes
new_nameserver.save!
domain_scope.delete_if { |i| i == domain.name || i == domain.name_puny } domains.delete_if { |i| i == domain.name || i == domain.name_puny }
domain_list << domain_name domain_list << domain_name
end end
self.domains.where(name: domain_list).find_each(&:update_whois_record) if domain_list.any?
[domain_list.uniq.sort, (domain_scope + failed_list).uniq.sort]
end end
def create_nameserver(domain, attributes)
new_nameserver = Nameserver.new
new_nameserver.domain = domain
new_nameserver.attributes = attributes
new_nameserver.save!
end end
def vat_country=(country) def vat_country=(country)