engine/lib/locomotive/heroku/custom_domain.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2010-06-14 13:04:01 +00:00
module Locomotive
module Heroku
module CustomDomain
2010-06-14 13:04:01 +00:00
extend ActiveSupport::Concern
2010-06-14 13:04:01 +00:00
included do
2010-06-14 13:04:01 +00:00
after_save :add_heroku_domains
after_destroy :remove_heroku_domains
2010-06-14 13:04:01 +00:00
alias_method_chain :add_subdomain_to_domains, :heroku
end
2010-06-14 13:04:01 +00:00
module InstanceMethods
2010-06-14 13:04:01 +00:00
protected
2010-06-14 13:04:01 +00:00
def add_subdomain_to_domains_with_heroku
unless self.domains_change.nil?
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
@heroku_domains_change = {
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
}
end
2010-06-14 13:04:01 +00:00
add_subdomain_to_domains_without_heroku
end
2010-06-14 13:04:01 +00:00
def add_heroku_domains
return if @heroku_domains_change.nil?
2010-06-14 13:04:01 +00:00
@heroku_domains_change[:added].each do |name|
Locomotive.add_heroku_domain(name)
end
@heroku_domains_change[:removed].each do |name|
Locomotive.remove_heroku_domain(name)
end
end
2010-06-14 13:04:01 +00:00
def remove_heroku_domains
self.domains_without_subdomain.each do |name|
Locomotive.remove_heroku_domain(name)
end
end
2010-06-14 13:04:01 +00:00
end
2010-06-14 13:04:01 +00:00
end
end
end