Class: RestPack::Core::Client::Cache
- Inherits:
-
Object
- Object
- RestPack::Core::Client::Cache
- Defined in:
- lib/restpack-core-client/cache.rb
Instance Attribute Summary collapse
-
#configurations ⇒ Object
Returns the value of attribute configurations.
Class Method Summary collapse
Instance Method Summary collapse
- #get_channel(host) ⇒ Object
- #get_channel_id(host) ⇒ Object
- #get_configuration(key) ⇒ Object
- #get_configuration_value(key, default_value = nil) ⇒ Object
-
#initialize(api) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(api) ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 12 |
# File 'lib/restpack-core-client/cache.rb', line 7 def initialize(api) @api = api @channel_ids = {} @channels = {} @configurations = api.root_configurations end |
Instance Attribute Details
#configurations ⇒ Object
Returns the value of attribute configurations.
5 6 7 |
# File 'lib/restpack-core-client/cache.rb', line 5 def configurations @configurations end |
Class Method Details
Instance Method Details
#get_channel(host) ⇒ Object
19 20 21 22 |
# File 'lib/restpack-core-client/cache.rb', line 19 def get_channel(host) channel_id = get_channel_id(host) @channels[channel_id] ||= @api.get_channel(channel_id) end |
#get_channel_id(host) ⇒ Object
24 25 26 |
# File 'lib/restpack-core-client/cache.rb', line 24 def get_channel_id(host) @channel_ids[host] ||= @api.get_domain(host)[:channel_id] end |
#get_configuration(key) ⇒ Object
28 29 30 |
# File 'lib/restpack-core-client/cache.rb', line 28 def get_configuration(key) @configurations.find { |c| c.key == key.to_s } end |
#get_configuration_value(key, default_value = nil) ⇒ Object
32 33 34 35 |
# File 'lib/restpack-core-client/cache.rb', line 32 def get_configuration_value(key, default_value = nil) config = get_configuration(key) config.nil? ? default_value : config.value end |