Class: Easybill::Configuration

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

Constant Summary collapse

OPTIONS =
%i(api_key logger).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



11
12
13
14
15
16
# File 'lib/easybill/configuration.rb', line 11

def initialize
  OPTIONS.each do |option|
    env_key = "EASYBILL_#{option.upcase}"
    send("#{option}=", ENV[env_key]) if ENV[env_key]
  end
end

Instance Attribute Details

#api_keyObject

The API key for your user taken from the easybill website.



6
7
8
# File 'lib/easybill/configuration.rb', line 6

def api_key
  @api_key
end

#loggerObject

The logger used by Easybill



9
10
11
# File 'lib/easybill/configuration.rb', line 9

def logger
  @logger
end

Instance Method Details

#[](key) ⇒ Object

Public: Allows config options to be read like a hash.

key - Name of the option to retrieve

Returns the value of the requested attribute



30
31
32
# File 'lib/easybill/configuration.rb', line 30

def[](key)
  send(key) if OPTIONS.include?(key)
end

#merge(hash) ⇒ Object

Public

hash - A set of configuration options that will take precedence over the defaults

Returns a hash of all configurable options merged with hash



39
40
41
# File 'lib/easybill/configuration.rb', line 39

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

#to_hashObject

Public: Returns a hash of all configurable options.



19
20
21
22
23
# File 'lib/easybill/configuration.rb', line 19

def to_hash
  Hash[OPTIONS.map do |option|
    [option, send(option)]
  end]
end