Class: InfoparkComponentCache::Component

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

Overview

Cache entity (component) consists of an obj, a name and some parameters (hash). It should be used to point to some data stored in a particular context

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, component, params = {}) ⇒ Component

Returns a new instance of Component.



10
11
12
# File 'lib/infopark_component_cache/component.rb', line 10

def initialize(obj, component, params={})
  @obj, @component, @params = obj, component, params
end

Instance Attribute Details

#component ⇒ Object (readonly)

Returns the value of attribute component.



8
9
10
# File 'lib/infopark_component_cache/component.rb', line 8

def component
  @component
end

#obj ⇒ Object (readonly)

Returns the value of attribute obj.



8
9
10
# File 'lib/infopark_component_cache/component.rb', line 8

def obj
  @obj
end

#params ⇒ Object (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/infopark_component_cache/component.rb', line 8

def params
  @params
end

Instance Method Details

#cache_key(meta_prefix = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/infopark_component_cache/component.rb', line 18

def cache_key(meta_prefix=nil)
  if meta_prefix
    meta_prefix + "_" + KeyGenerator.generate_key(identity_hash)
  else
    KeyGenerator.generate_key(identity_hash)
  end
end

#identity_hash ⇒ Object



26
27
28
# File 'lib/infopark_component_cache/component.rb', line 26

def identity_hash
  @params.merge({:obj_name=>@obj.name, :obj_id=>@obj.id, :obj_component=>@component})
end

#name ⇒ Object



14
15
16
# File 'lib/infopark_component_cache/component.rb', line 14

def name
  self.component
end