Class: JSONAPIHelpers::Serializers::Relationships
- Inherits:
-
Object
- Object
- JSONAPIHelpers::Serializers::Relationships
- Defined in:
- lib/jsonapi_helpers/serializers/relationships.rb
Instance Method Summary collapse
- #add(relation:, id:, type:) ⇒ Object
-
#initialize ⇒ Relationships
constructor
A new instance of Relationships.
- #to_h ⇒ Object
-
#to_json(_context = nil) ⇒ Object
Rails is awkward and calls #to_json with a context argument NOTE: Rails only method Hash#to_json.
Constructor Details
#initialize ⇒ Relationships
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_h ⇒ Object
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 |