Class: Exchange::Configuration
- Inherits:
-
Object
- Object
- Exchange::Configuration
- Defined in:
- lib/exchange/configuration.rb
Overview
A configuration class that stores the configuration of the gem. It allows to set the api from which the data gets retrieved, the cache in which the data gets cached, the regularity of updates for the currency rates, how many times the api calls should be retried on failure, and wether operations mixing currencies should raise errors or not
Constant Summary collapse
- DEFAULTS =
The configuration defaults
{ :api => { :subclass => ExternalAPI::XavierMedia, :retries => 7, :protocol => :http, :app_id => nil, :fallback => ExternalAPI::Ecb }, :cache => { :subclass => Cache::Memory, :expire => :daily, :path => nil, :host => nil, :port => nil }, :implicit_conversions => true }
Instance Method Summary collapse
-
#api ⇒ Exchange::ExternalAPI::Configuration
Getter for the api configuration.
-
#cache ⇒ Exchange::Cache::Configuration
Getter for the cache configuration.
-
#implicit_conversions ⇒ Boolean
Getter for the implicit Conversions configuration.
-
#implicit_conversions=(data) ⇒ Boolean
Setter for the implicit conversions configuration.
-
#initialize(configuration = {}, &block) ⇒ Configuration
constructor
Initialize a new configuration.
-
#reset ⇒ Object
Allows to reset the configuration to the defaults.
Constructor Details
#initialize(configuration = {}, &block) ⇒ Configuration
Initialize a new configuration. Takes a hash and/or a block. Lets you easily set the configuration the way you want it to be
107 108 109 110 111 |
# File 'lib/exchange/configuration.rb', line 107 def initialize configuration={}, &block @config = DEFAULTS.merge(configuration) self.instance_eval(&block) if block_given? super() end |
Instance Method Details
#api ⇒ Exchange::ExternalAPI::Configuration
Getter for the api configuration. Instantiates the configuration as an open struct, if called for the first time. Also camelizes and constantizes the api subclass, if used for the first time.
173 |
# File 'lib/exchange/configuration.rb', line 173 install_getter :api |
#cache ⇒ Exchange::Cache::Configuration
Getter for the cache configuration. Instantiates the configuration as an open struct, if called for the first time. Also camelizes and constantizes the cache subclass, if used for the first time.
179 |
# File 'lib/exchange/configuration.rb', line 179 install_getter :cache |
#implicit_conversions ⇒ Boolean
Getter for the implicit Conversions configuration. If set to true, implicit conversions will not raise errors If set to false, implicit conversions will raise errors
129 130 131 |
# File 'lib/exchange/configuration.rb', line 129 def implicit_conversions @config[:implicit_conversions] end |
#implicit_conversions=(data) ⇒ Boolean
Setter for the implicit conversions configuration. If set to true, implicit conversions will not raise errors If set to false, implicit conversions will raise errors
140 141 142 |
# File 'lib/exchange/configuration.rb', line 140 def implicit_conversions= data @config[:implicit_conversions] = data end |
#reset ⇒ Object
Allows to reset the configuration to the defaults
117 118 119 120 121 |
# File 'lib/exchange/configuration.rb', line 117 def reset api.reset cache.reset self.implicit_conversions = DEFAULTS[:implicit_conversions] end |