Class: EasySerializer::Cacher::Collection
- Inherits:
-
Template
- Object
- Template
- EasySerializer::Cacher::Collection
show all
- Defined in:
- lib/easy_serializer/cacher/collection.rb
Instance Attribute Summary
Attributes inherited from Template
#metadata, #serializer
Instance Method Summary
collapse
Methods inherited from Template
call, #initialize
Methods included from Helpers
#option_to_value
Instance Method Details
#block_to_get_value(elem) ⇒ Object
27
28
29
|
# File 'lib/easy_serializer/cacher/collection.rb', line 27
def block_to_get_value(elem)
proc { nested_serializer.call(elem) }
end
|
#collection ⇒ Object
11
12
13
|
# File 'lib/easy_serializer/cacher/collection.rb', line 11
def collection
@collection ||= serializer.instance_exec serializer.object, &metadata.get_value
end
|
#execute ⇒ Object
5
6
7
8
9
|
# File 'lib/easy_serializer/cacher/collection.rb', line 5
def execute
collection.map do |elem|
fetch(key(elem), elem)
end
end
|
#fetch(key, elem) ⇒ Object
35
36
37
|
# File 'lib/easy_serializer/cacher/collection.rb', line 35
def fetch(key, elem)
EasySerializer.cache.fetch(key, options, &block_to_get_value(elem))
end
|
#key(elem) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/easy_serializer/cacher/collection.rb', line 15
def key(elem)
if metadata_key
[elem, metadata_key, nested_serializer.name]
else
[elem, nested_serializer.name]
end.flatten
end
|
#nested_serializer ⇒ Object
31
32
33
|
# File 'lib/easy_serializer/cacher/collection.rb', line 31
def nested_serializer
metadata.serializer(serializer.object, serializer)
end
|
#options ⇒ Object
23
24
25
|
# File 'lib/easy_serializer/cacher/collection.rb', line 23
def options
metadata.cache_options || {}
end
|