Class: JSONAPI::CachedResponseFragment::Write

Inherits:
Struct
  • Object
show all
Defined in:
lib/jsonapi/cached_response_fragment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def context
  @context
end

#context_keyObject

Returns the value of attribute context_key

Returns:

  • (Object)

    the current value of context_key



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def context_key
  @context_key
end

#relationship_dataObject

Returns the value of attribute relationship_data

Returns:

  • (Object)

    the current value of relationship_data



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def relationship_data
  @relationship_data
end

#resourceObject

Returns the value of attribute resource

Returns:

  • (Object)

    the current value of resource



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def resource
  @resource
end

#resource_klassObject

Returns the value of attribute resource_klass

Returns:

  • (Object)

    the current value of resource_klass



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def resource_klass
  @resource_klass
end

#serializerObject

Returns the value of attribute serializer

Returns:

  • (Object)

    the current value of serializer



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def serializer
  @serializer
end

#serializer_config_keyObject

Returns the value of attribute serializer_config_key

Returns:

  • (Object)

    the current value of serializer_config_key



17
18
19
# File 'lib/jsonapi/cached_response_fragment.rb', line 17

def serializer_config_key
  @serializer_config_key
end

Instance Method Details

#to_key_valueObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jsonapi/cached_response_fragment.rb', line 18

def to_key_value

  (id, cache_key) = resource.cache_id

  json = serializer.object_hash(resource, relationship_data)

  cr = CachedResponseFragment.new(
    resource_klass,
    id,
    json['type'],
    context,
    resource.fetchable_fields,
    json['relationships'],
    json['links'],
    json['attributes'],
    json['meta']
  )

  key = [resource_klass._type, id, cache_key, serializer_config_key, context_key]

  [key, cr]
end