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
26
27
28
29
30
31
32
# 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.inject({}) do |memo,resource_pair|
    resource_key, resources = resource_pair[0], resource_pair[1]
    
    fs_resource_array = memo[resource_key] ||= []
    klass_name = Flareshow::ResourceToClassMap[resource_key]
    if klass_name
      klass = Kernel.const_get(klass_name)
      if klass
        resources.each 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)
          fs_resource_array << item
        end
      end
    end
    memo
  end
end

.cacheObject

get the managed cache object



35
36
37
# File 'lib/cache.rb', line 35

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