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
- #execute ⇒ Object
- #fetch ⇒ Object
-
#initialize(serializer, &block) ⇒ RootCacher
constructor
A new instance of RootCacher.
- #key ⇒ Object
- #object ⇒ Object
- #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
#execute ⇒ Object
15 16 17 |
# File 'lib/easy_serializer/root_cacher.rb', line 15 def execute fetch end |
#fetch ⇒ Object
41 42 43 |
# File 'lib/easy_serializer/root_cacher.rb', line 41 def fetch EasySerializer.cache.fetch(key, , &block) end |
#key ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/easy_serializer/root_cacher.rb', line 31 def key custom_key = serializer.__cache[:key] if custom_key k = option_to_value(custom_key, object, serializer) [object, k, serializer.class.name] else [object, serializer.class.name] end.flatten end |
#object ⇒ Object
19 20 21 |
# File 'lib/easy_serializer/root_cacher.rb', line 19 def object serializer.object end |
#options ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/easy_serializer/root_cacher.rb', line 23 def h = serializer.__cache.dup [:block, :cache_key, :root_call, :serializer, :key].each do |k| h.delete(k) end h end |