Module: Jat::Plugins::JsonApi::ResponsePiece::InstanceMethods

Included in:
Jat::Plugins::JsonApi::ResponsePiece
Defined in:
lib/jat/plugins/json_api/lib/response_piece.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def context
  @context
end

#includesObject (readonly)

Returns the value of attribute includes.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def includes
  @includes
end

#jat_classObject (readonly)

Returns the value of attribute jat_class.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def jat_class
  @jat_class
end

#mapObject (readonly)

Returns the value of attribute map.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def map
  @map
end

#objectObject (readonly)

Returns the value of attribute object.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def object
  @object
end

#type_mapObject (readonly)

Returns the value of attribute type_map.



14
15
16
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 14

def type_map
  @type_map
end

Instance Method Details

#initialize(object, context, map, includes) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 16

def initialize(object, context, map, includes)
  @jat_class = self.class.jat_class
  @object = object
  @context = context
  @map = map
  @type_map = map.fetch(jat_class.get_type)
  @includes = includes
end

#to_hObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 25

def to_h
  return unless object

  attributes = get_attributes
  relationships = get_relationships
  links = get_links
  meta = get_meta

  result = uid
  result[:attributes] = attributes if attributes
  result[:relationships] = relationships if relationships
  result[:links] = links if links.any?
  result[:meta] = meta if meta.any?
  result
end

#uidObject



41
42
43
# File 'lib/jat/plugins/json_api/lib/response_piece.rb', line 41

def uid
  {type: type, id: id}
end