Sha256: 9afa755996b2bc9cd0ce281b2525e3bed474ac5151e557eac95fd9b5848d6b4a

Contents?: true

Size: 1.58 KB

Versions: 13

Compression:

Stored size: 1.58 KB

Contents

require 'heroku'
require 'heroku/client'
require 'locomotive/heroku/custom_domain'

module Locomotive
  module Heroku

    extend ActiveSupport::Concern

    included do
      class << self
        attr_accessor :heroku_connection
        attr_accessor :heroku_domains
      end
    end

    module ClassMethods

      def heroku?
        !self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
      end

      def enable_heroku
        raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?

        self.open_heroku_connection
        self.enhance_site_model

        # "cache" domains for better performance
        self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
      end

      def open_heroku_connection
        login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
        password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']

        self.heroku_connection = ::Heroku::Client.new(login, password)
      end

      def enhance_site_model
        Site.send :include, Locomotive::Heroku::CustomDomain
      end

      # manage domains

      def add_heroku_domain(name)
        Locomotive.logger "[add heroku domain] #{name}"
        self.heroku_connection.add_domain(self.config.heroku[:name], name)
        self.heroku_domains << name
      end

      def remove_heroku_domain(name)
        Locomotive.logger "[remove heroku domain] #{name}"
        self.heroku_connection.remove_domain(self.config.heroku[:name], name)
        self.heroku_domains.delete(name)
      end

    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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