Class: Easybill::Configuration
- Inherits:
-
Object
- Object
- Easybill::Configuration
- Defined in:
- lib/easybill/configuration.rb
Constant Summary collapse
- OPTIONS =
%i(api_key logger).freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
The API key for your user taken from the easybill website.
-
#logger ⇒ Object
The logger used by Easybill.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Public: Allows config options to be read like a hash.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge(hash) ⇒ Object
Public.
-
#to_hash ⇒ Object
Public: Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
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}" public_send("#{option}=", ENV[env_key]) if ENV[env_key] end end |
Instance Attribute Details
#api_key ⇒ Object
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 |
#logger ⇒ Object
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) public_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_hash ⇒ Object
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, public_send(option)] end] end |