Module: Ashby::Configuration
- Included in:
- Ashby
- Defined in:
- lib/ashby/configuration.rb
Overview
Ashby::Configuration manages global settings for the Ashby API client.
This module is intended to be extended by a class or module that needs to hold configuration settings such as the API token.
Example:
Ashby::Configuration.configure do |config|
config.api_token = 'your-token'
end
Ashby::Configuration.config
# => { api_token: 'your-token' }
Constant Summary collapse
- VALID_OPTIONS_KEYS =
%i[api_token].freeze
Class Method Summary collapse
-
.extended(base) ⇒ Object
Sets all configuration options to their default values when this module is extended.
Instance Method Summary collapse
- #config ⇒ Object
- #configure {|_self| ... } ⇒ Object
-
#reset ⇒ Object
Resets all configuration options to the defaults.
Class Method Details
.extended(base) ⇒ Object
Sets all configuration options to their default values when this module is extended.
23 24 25 |
# File 'lib/ashby/configuration.rb', line 23 def self.extended(base) base.reset end |
Instance Method Details
#config ⇒ Object
31 32 33 34 35 |
# File 'lib/ashby/configuration.rb', line 31 def config VALID_OPTIONS_KEYS.inject({}) do |option, key| option.merge!(key => send(key)) end end |
#configure {|_self| ... } ⇒ Object
27 28 29 |
# File 'lib/ashby/configuration.rb', line 27 def configure yield self end |
#reset ⇒ Object
Resets all configuration options to the defaults.
38 39 40 |
# File 'lib/ashby/configuration.rb', line 38 def reset self.api_token = nil end |