Class: ActiveModel::Serializer::Adapter::FragmentCache
- Inherits:
-
Object
- Object
- ActiveModel::Serializer::Adapter::FragmentCache
- Defined in:
- lib/active_model/serializer/adapter/fragment_cache.rb
Instance Attribute Summary (collapse)
-
- (Object) serializer
readonly
Returns the value of attribute serializer.
Instance Method Summary (collapse)
- - (Object) fetch
-
- (FragmentCache) initialize(adapter, serializer, options)
constructor
A new instance of FragmentCache.
Constructor Details
- (FragmentCache) initialize(adapter, serializer, options)
Returns a new instance of FragmentCache
7 8 9 10 11 |
# File 'lib/active_model/serializer/adapter/fragment_cache.rb', line 7 def initialize(adapter, serializer, ) @instance_options = @adapter = adapter @serializer = serializer end |
Instance Attribute Details
- (Object) serializer (readonly)
Returns the value of attribute serializer
5 6 7 |
# File 'lib/active_model/serializer/adapter/fragment_cache.rb', line 5 def serializer @serializer end |
Instance Method Details
- (Object) fetch
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_model/serializer/adapter/fragment_cache.rb', line 13 def fetch klass = serializer.class # It will split the serializer into two, one that will be cached and other wont serializers = fragment_serializer(serializer.object.class.name, klass) # Instanciate both serializers cached_serializer = serializers[:cached].constantize.new(serializer.object) non_cached_serializer = serializers[:non_cached].constantize.new(serializer.object) cached_adapter = adapter.class.new(cached_serializer, ) non_cached_adapter = adapter.class.new(non_cached_serializer, ) # Get serializable hash from both cached_hash = cached_adapter.serializable_hash non_cached_hash = non_cached_adapter.serializable_hash # Merge both results adapter.fragment_cache(cached_hash, non_cached_hash) end |