Module: Graphiti::ActiveGraph::Util::SerializerRelationship

Defined in:
lib/graphiti/active_graph/util/serializer_relationship.rb

Instance Method Summary collapse

Instance Method Details

#data_procObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphiti/active_graph/util/serializer_relationship.rb', line 4

def data_proc
  sideload_ref = @sideload
  ->(_) {
    # use custom assigned sideload if it is specified via "assign_each_proc"
    # otherwise retrieve sideload using normal getter on parent object
    records = if custom_proc = sideload_ref.assign_each_proc
                custom_proc.call(@object)
              else
                @object.public_send(sideload_ref.association_name)
              end

    if records
      if records.respond_to?(:to_ary)
        records.each { |r| sideload_ref.resource.decorate_record(r) }
      else
        sideload_ref.resource.decorate_record(records)
      end

      records
    end
  }
end