Class: EasySerializer::RootCacher
- Inherits:
-
Object
- Object
- EasySerializer::RootCacher
- Includes:
- Helpers
- Defined in:
- lib/easy_serializer/root_cacher.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #execute ⇒ Object
- #fetch ⇒ Object
-
#initialize(serializer, &block) ⇒ RootCacher
constructor
A new instance of RootCacher.
- #key ⇒ Object
- #object ⇒ Object (also: #subject)
- #options ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(serializer, &block) ⇒ RootCacher
Returns a new instance of RootCacher.
10 11 12 13 |
# File 'lib/easy_serializer/root_cacher.rb', line 10 def initialize(serializer, &block) @serializer = serializer @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/easy_serializer/root_cacher.rb', line 9 def block @block end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
9 10 11 |
# File 'lib/easy_serializer/root_cacher.rb', line 9 def serializer @serializer end |
Class Method Details
.call(serializer, &block) ⇒ Object
5 6 7 |
# File 'lib/easy_serializer/root_cacher.rb', line 5 def self.call(serializer, &block) new(serializer, &block).execute end |
Instance Method Details
#cache_key ⇒ Object
24 25 26 27 |
# File 'lib/easy_serializer/root_cacher.rb', line 24 def cache_key return object.cache_key if object.respond_to?(:cache_key) object end |
#execute ⇒ Object
15 16 17 |
# File 'lib/easy_serializer/root_cacher.rb', line 15 def execute fetch end |
#fetch ⇒ Object
47 48 49 |
# File 'lib/easy_serializer/root_cacher.rb', line 47 def fetch EasySerializer.cache.fetch(key, , &block) end |
#key ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/easy_serializer/root_cacher.rb', line 37 def key custom_key = serializer.__cache[:key] if custom_key k = option_to_value(custom_key, object, serializer) [cache_key, k, serializer.class.name] else [cache_key, serializer.class.name] end.flatten end |
#object ⇒ Object Also known as: subject
19 20 21 |
# File 'lib/easy_serializer/root_cacher.rb', line 19 def object serializer.object end |
#options ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/easy_serializer/root_cacher.rb', line 29 def h = serializer.__cache.dup [:block, :cache_key, :root_call, :serializer, :key].each do |k| h.delete(k) end h end |