Class: Flareshow::CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cache.rb

Overview

provides an interface for various caches that flareshow might use

Class Method Summary collapse

Class Method Details

.assimilate_resources(data) ⇒ Object

assimilate the resources provided in the response



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cache.rb', line 7

def assimilate_resources(data)
  # process each resource key and generate a new object
  # or merge the object data with an existing object
  data.each do |resource_pair|
    resource_key, resources = resource_pair[0], resource_pair[1]
    klass = Kernel.const_get(Flareshow::ResourceToClassMap[resource_key])
    next unless klass
    resources = resources.map do |resource_data|
      item = cache.get_resource(resource_key, resource_data["id"])
      if item
        item.update(resource_data, :server)
      else
        item = klass.new(resource_data, :server) 
      end
      cache.set_resource(resource_key, item.id, item)
      item
    end
  end
end

.cacheObject

get the managed cache object



28
29
30
# File 'lib/cache.rb', line 28

def cache
  @cache ||= Flareshow::Cache.new
end