Method: JSONAPI::CachedResponseFragment#initialize

Defined in:
lib/jsonapi/cached_response_fragment.rb

#initialize(resource_klass, id, type, context, fetchable_fields, relationships, links_json, attributes_json, meta_json) ⇒ CachedResponseFragment

Returns a new instance of CachedResponseFragment.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jsonapi/cached_response_fragment.rb', line 45

def initialize(resource_klass, id, type, context, fetchable_fields, relationships,
               links_json, attributes_json, meta_json)
  @resource_klass = resource_klass
  @id = id
  @type = type
  @context = context
  @fetchable_fields = Set.new(fetchable_fields)

  # Relationships left uncompiled because we'll often want to insert included ids on retrieval
  # Remove the data since that should not be cached
  @relationships = relationships&.transform_values {|v| v.delete_if {|k, _v| k == 'data'} }
  @links_json = CompiledJson.of(links_json)
  @attributes_json = CompiledJson.of(attributes_json)
  @meta_json = CompiledJson.of(meta_json)
end