Sha256: c9fd9884ff783f03f3314a6e6648b406a2ff0c9233ef448b3849cbec2a05e585

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

module Jumpup
  module Heroku

    class << self
      attr_accessor :configuration
    end

    def self.configure
      self.configuration ||= Configuration.new
      yield(configuration)
    end


    class Configuration
      attr_accessor :app, :staging_app, :production_app, :run_database_tasks, :host

      def initialize
        @run_database_tasks ||= true
        @host ||= 'heroku.com'
      end

      def account(account_token)
        if account_token == current_account
          self.app = nil
          self.host = "heroku.#{account_token}"
          yield(self)
        end
      end

      def valid?
        boolean_run_database_tasks? && (only_app? || only_production_and_staging_apps?)
      end

      def deploy_branch
        'master'
      end

      def deploy_to_production_branch
        return 'production' if production_app
        'master'
      end

      private

        def current_account
          (ENV["HEROKU_ACCOUNT"] || %x{ git config heroku.account }.chomp).to_sym
        end

        def only_app?
          app && staging_app.nil? && production_app.nil?
        end

        def only_production_and_staging_apps?
          staging_app && production_app && app.nil?
        end

        def boolean_run_database_tasks?
          run_database_tasks.is_a?(TrueClass) || run_database_tasks.is_a?(FalseClass)
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jumpup-heroku-0.0.6 lib/jumpup/heroku/configuration.rb
jumpup-heroku-0.0.5 lib/jumpup/heroku/configuration.rb