Class: GithubHerokuDeployer::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/github_heroku_deployer/configuration.rb

Constant Summary collapse

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"]
}

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes defaults to be the environment varibales of the same names



20
21
22
23
24
# File 'lib/github_heroku_deployer/configuration.rb', line 20

def initialize
  OPTIONS.each_pair do |key, value|
    self.send("#{key}=", value)
  end
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



29
30
31
# File 'lib/github_heroku_deployer/configuration.rb', line 29

def [](option)
  send(option)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

precedence over the defaults

Parameters:

  • hash (Hash)

    A set of configuration options that will take



46
47
48
# File 'lib/github_heroku_deployer/configuration.rb', line 46

def merge(hash)
  to_hash.merge(hash)
end

#to_hashObject

Returns a hash of all configurable options



34
35
36
37
38
39
40
# File 'lib/github_heroku_deployer/configuration.rb', line 34

def to_hash
  OPTIONS.inject({}) do |hash, option|
    key = option.first
    hash[key] = self.send(key)
    hash
  end
end

#validate_presence(options) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/github_heroku_deployer/configuration.rb', line 50

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