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
- 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)
-
- (Exchange::ExternalAPI::Configuration) api
Getter for the api configuration.
-
- (Exchange::Cache::Configuration) cache
Getter for the cache configuration.
-
- (Boolean) implicit_conversions
Getter for the implicit Conversions configuration.
-
- (Boolean) implicit_conversions=(data)
Setter for the implicit conversions configuration.
-
- (Configuration) initialize(configuration = {}, &block)
constructor
Initialize a new configuration.
-
- (Object) reset
Allows to reset the configuration to the defaults.
Constructor Details
- (Configuration) initialize(configuration = {}, &block)
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
- (Exchange::ExternalAPI::Configuration) api
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 |
- (Exchange::Cache::Configuration) cache
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 |
- (Boolean) implicit_conversions
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 |
- (Boolean) implicit_conversions=(data)
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 |
- (Object) reset
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 |