Class: ActiveModelSerializers::FragmentCache
- Inherits:
-
Object
- Object
- ActiveModelSerializers::FragmentCache
- Defined in:
- lib/active_model_serializers/fragment_cache.rb
Instance Attribute Summary (collapse)
-
- (Object) serializer
readonly
Returns the value of attribute serializer.
Instance Method Summary (collapse)
-
- (Object) fetch
1.
-
- (FragmentCache) initialize(adapter, serializer, options)
constructor
A new instance of FragmentCache.
Constructor Details
- (FragmentCache) initialize(adapter, serializer, options)
Returns a new instance of FragmentCache
5 6 7 8 9 |
# File 'lib/active_model_serializers/fragment_cache.rb', line 5 def initialize(adapter, serializer, ) @instance_options = @adapter = adapter @serializer = serializer end |
Instance Attribute Details
- (Object) serializer (readonly)
Returns the value of attribute serializer
3 4 5 |
# File 'lib/active_model_serializers/fragment_cache.rb', line 3 def serializer @serializer end |
Instance Method Details
- (Object) fetch
-
Create a CachedSerializer and NonCachedSerializer from the serializer class
-
Serialize the above two with the given adapter
-
Pass their serializations to the adapter
::fragment_cache
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_model_serializers/fragment_cache.rb', line 14 def fetch object = serializer.object # It will split the serializer into two, one that will be cached and one that will not serializers = fragment_serializer # Get serializable hash from both cached_hash = serialize(object, serializers[:cached]) non_cached_hash = serialize(object, serializers[:non_cached]) # Merge both results adapter.fragment_cache(cached_hash, non_cached_hash) end |