Class: JsonapiCompliable::Util::RelationshipPayload Private
- Inherits:
-
Object
- Object
- JsonapiCompliable::Util::RelationshipPayload
- Defined in:
- lib/jsonapi_compliable/util/relationship_payload.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Helper methods for traversing the 'relationships' JSONAPI payloads
Instance Attribute Summary collapse
- #payload ⇒ Object readonly private
- #resource ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(resource, payload, only: [], except: []) ⇒ RelationshipPayload
constructor
private
A new instance of RelationshipPayload.
- #iterate ⇒ Object private
Constructor Details
#initialize(resource, payload, only: [], except: []) ⇒ RelationshipPayload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RelationshipPayload
15 16 17 18 19 20 |
# File 'lib/jsonapi_compliable/util/relationship_payload.rb', line 15 def initialize(resource, payload, only: [], except: []) @resource = resource @payload = payload @only = only @except = except end |
Instance Attribute Details
#payload ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/jsonapi_compliable/util/relationship_payload.rb', line 6 def payload @payload end |
#resource ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/jsonapi_compliable/util/relationship_payload.rb', line 6 def resource @resource end |
Class Method Details
.iterate(resource:, relationships: {}, only: [], except: []) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 11 12 13 |
# File 'lib/jsonapi_compliable/util/relationship_payload.rb', line 8 def self.iterate(resource:, relationships: {}, only: [], except: []) instance = new(resource, relationships, only: only, except: except) instance.iterate do |sideload, relationship_data, sub_relationships| yield sideload, relationship_data, sub_relationships end end |
Instance Method Details
#iterate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jsonapi_compliable/util/relationship_payload.rb', line 22 def iterate payload.each_pair do |relationship_name, relationship_payload| if sl = resource.sideload(relationship_name.to_sym) if should_yield?(sl.type) if relationship_payload.is_a?(Array) relationship_payload.each do |rp| yield payload_for(sl, rp) end else yield payload_for(sl, relationship_payload) end end end end end |