Sha256: b2409246fceb56109ce80409071ea7e08be64546e1e304323956b99423473a8c

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

module GithubHerokuDeployer
  class Configuration
    OPTIONS = {
      github_repo: ENV["GITHUB_REPO"],
      heroku_api_key: ENV["HEROKU_API_KEY"],
      heroku_app_name: ENV["HEROKU_APP_NAME"],
      heroku_repo: ENV["HEROKU_REPO"],
      heroku_username: ENV["HEROKU_USERNAME"],
      id_rsa: ENV["ID_RSA"],
      logger: ::Logger.new(STDOUT),
      repo_dir: ENV["REPO_DIR"]
    }

    # Defines accessors for all OPTIONS
    OPTIONS.each_pair do |key, value|
      attr_accessor key
    end

    # Initializes defaults to be the environment varibales of the same names
    def initialize
      OPTIONS.each_pair do |key, value|
        self.send("#{key}=", value)
      end
    end

    # Allows config options to be read like a hash
    #
    # @param [Symbol] option Key for a given attribute
    def [](option)
      send(option)
    end

    # Returns a hash of all configurable options
    def to_hash
      OPTIONS.inject({}) do |hash, option|
        key = option.first
        hash[key] = self.send(key)
        hash
      end
    end

    # Returns a hash of all configurable options merged with +hash+
    #
    # @param [Hash] hash A set of configuration options that will take 
    # precedence over the defaults
    def merge(hash)
      to_hash.merge(hash)
    end

    def validate_presence(options)
      OPTIONS.each_pair do |key, value|
        if options[key].nil?
          raise GithubHerokuDeployer::ConfigurationException, "#{key} is missing"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
github_heroku_deployer-0.4.1 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.4.0 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.3.1 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.3.0 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.2.1 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.2.0 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.9 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.8 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.7 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.6 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.5 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.4 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.3 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.2 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.1 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.1.0 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.0.5 lib/github_heroku_deployer/configuration.rb