Class: JSONAPIHelpers::Serializers::Relationships

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_helpers/serializers/relationships.rb

Instance Method Summary collapse

Constructor Details

#initializeRelationships

Returns a new instance of Relationships.



8
9
10
# File 'lib/jsonapi_helpers/serializers/relationships.rb', line 8

def initialize
  @relationships = {}
end

Instance Method Details

#add(relation:, id:, type:) ⇒ Object



12
13
14
# File 'lib/jsonapi_helpers/serializers/relationships.rb', line 12

def add(relation:, id:, type:)
  @relationships[relation] = { id: id, type: type }
end

#to_hObject



16
17
18
# File 'lib/jsonapi_helpers/serializers/relationships.rb', line 16

def to_h
  @relationships
end

#to_json(_context = nil) ⇒ Object

Rails is awkward and calls #to_json with a context argument NOTE: Rails only method Hash#to_json



22
23
24
# File 'lib/jsonapi_helpers/serializers/relationships.rb', line 22

def to_json(_context = nil)
  to_h.to_json
end