Refactored whois models to a module and subclasses

This commit is contained in:
Andres Keskküla 2014-12-08 17:01:17 +02:00
parent 67519a46f4
commit 00837452a8
11 changed files with 48 additions and 23 deletions

View file

@ -11,13 +11,18 @@ module DomainVersionObserver
name = domain_name
return unless name
body = snapshot
delay.update_whois(name, body)
delay.update_private_whois(name, body)
delay.update_public_whois(name, body)
end
# not sure we need to pass in the params since i don't know if delayed job has access to
# all the regular attributes and stuff
def update_whois(domain_name, body)
wd = WhoisDomain.find_or_initialize_by(name: domain_name)
def update_private_whois(domain_name, body)
wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name)
wd.body = body
wd.save!
end
def update_public_whois(domain_name, body)
wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name)
wd.body = body
wd.save!
end

2
app/models/whois.rb Normal file
View file

@ -0,0 +1,2 @@
module Whois
end

View file

@ -0,0 +1,5 @@
module Whois
class PrivateDomain < PrivateServer
self.table_name = 'domains'
end
end

View file

@ -0,0 +1,6 @@
module Whois
class PrivateServer < ActiveRecord::Base
self.abstract_class = true
establish_connection :"#{Rails.env}_private_whois"
end
end

View file

@ -0,0 +1,5 @@
module Whois
class PublicDomain < PublicServer
self.table_name = 'domains'
end
end

View file

@ -0,0 +1,6 @@
module Whois
class PublicServer < ActiveRecord::Base
self.abstract_class = true
establish_connection :"#{Rails.env}_public_whois"
end
end

View file

@ -1,3 +0,0 @@
class WhoisDomain < WhoisPrivateServer
self.table_name = 'domains'
end

View file

@ -1,4 +0,0 @@
class WhoisPrivateServer < ActiveRecord::Base
self.abstract_class = true
establish_connection :"#{Rails.env}_private_whois"
end

View file

@ -1,3 +0,0 @@
class WhoisDomain < WhoisPublicServer
self.table_name = 'domains'
end

View file

@ -1,4 +0,0 @@
class WhoisPublicServer < ActiveRecord::Base
self.abstract_class = true
establish_connection :"#{Rails.env}_public_whois"
end

View file

@ -18,8 +18,18 @@ production:
<<: *default
database: registry_production
development_whois:
database: whois_development
development_private_whois:
<<: *default
database: whois_private
test_whois:
database: test_whois
development_private_whois:
<<: *default
database: whois_public
production_public_whois:
<<: *default
database: production_whois_public
production_private_whois:
<<: *default
database: production_whois_private