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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#objObject (readonly)

Returns the value of attribute obj.



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

def obj
  @obj
end

#paramsObject (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



14
15
16
17
18
19
20
# File 'lib/infopark_component_cache/component.rb', line 14

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_hashObject



22
23
24
# File 'lib/infopark_component_cache/component.rb', line 22

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