Sha256: ed565629d1dc25545af9204fd3c85d223c491b4abcf62eed38acfd63145cb8c0

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 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"],
      ssh_enabled: false,
    }

    # 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

3 entries across 3 versions & 1 rubygems

Version Path
github_heroku_deployer-0.0.3 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.0.2 lib/github_heroku_deployer/configuration.rb
github_heroku_deployer-0.0.1 lib/github_heroku_deployer/configuration.rb