Class: HerokuResqueAutoscaler::Configuration

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

Constant Summary collapse

OPTIONS =
{
  heroku_api_key: ENV["HEROKU_API_KEY"],
  heroku_app_name: ENV["HEROKU_APP_NAME"],
  max_resque_workers: ENV["MAX_RESQUE_WORKERS"]
}

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes defaults to be the environment variables of the same names



15
16
17
18
19
# File 'lib/heroku_resque_autoscaler/configuration.rb', line 15

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



24
25
26
# File 'lib/heroku_resque_autoscaler/configuration.rb', line 24

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



41
42
43
# File 'lib/heroku_resque_autoscaler/configuration.rb', line 41

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

#to_hashObject

Returns a hash of all configurable options



29
30
31
32
33
34
35
# File 'lib/heroku_resque_autoscaler/configuration.rb', line 29

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