Sha256: 54d893091ba6173269566c96a476a6f3dc56361e00282569c51bb4bbc04f4cbf

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

module Locomotive
  module Heroku
    module CustomDomain

      extend ActiveSupport::Concern

      included do

        after_save :add_heroku_domains
        after_destroy :remove_heroku_domains

        alias_method_chain :add_subdomain_to_domains, :heroku
      end

      module InstanceMethods

        protected

        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

          add_subdomain_to_domains_without_heroku
        end

        def add_heroku_domains
          return if @heroku_domains_change.nil?

          @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

        def remove_heroku_domains
          self.domains_without_subdomain.each do |name|
            Locomotive.remove_heroku_domain(name)
          end
        end

      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-1.0.0.beta lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta12 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta11 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta10 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta9 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta8 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta7 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta5 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/heroku/custom_domain.rb
locomotive_cms-0.0.4 lib/locomotive/heroku/custom_domain.rb