Class: Graphiti::Util::RelationshipPayload Private

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/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

Class Method Summary collapse

Instance Method Summary collapse

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/graphiti/util/relationship_payload.rb', line 15

def initialize(resource, payload, only: [], except: [])
  @resource = resource
  @payload = payload
  @only = only
  @except = except
end

Instance Attribute Details

#payloadObject (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/graphiti/util/relationship_payload.rb', line 6

def payload
  @payload
end

#resourceObject (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/graphiti/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/graphiti/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

#iterateObject

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/graphiti/util/relationship_payload.rb', line 22

def iterate
  payload.each_pair do |relationship_name, relationship_payload|
    if (sl = resource.class.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