Class: ActiveModelSerializers::Adapter::JsonApi::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model_serializers/adapter/json_api/relationship.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_serializer, serializable_resource_options, association) ⇒ Relationship



11
12
13
14
15
# File 'lib/active_model_serializers/adapter/json_api/relationship.rb', line 11

def initialize(parent_serializer, serializable_resource_options, association)
  @parent_serializer = parent_serializer
  @association = association
  @serializable_resource_options = serializable_resource_options
end

Instance Method Details

#as_jsonObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_model_serializers/adapter/json_api/relationship.rb', line 17

def as_json
  hash = {}

  hash[:data] = data_for(association) if association.include_data?

  links = links_for(association)
  hash[:links] = links if links.any?

  meta = meta_for(association)
  hash[:meta] = meta if meta
  hash[:meta] = {} if hash.empty?

  hash
end