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


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

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


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

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