Class: RestPack::Core::Client::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/restpack-core-client/cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#configurationsObject

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

.create(domain, access_key) ⇒ Object



14
15
16
17
# File 'lib/restpack-core-client/cache.rb', line 14

def self.create(domain, access_key)
  api = RestPack::Core::Client::API.new(domain, access_key)
  Cache.new(api)
end

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