Class: Graphable::ThroughEdgeCreator

Inherits:
EdgeCreator show all
Defined in:
lib/graphable/edge_creator.rb

Instance Method Summary collapse

Methods inherited from EdgeCreator

#initialize, through, via

Constructor Details

This class inherits a constructor from Graphable::EdgeCreator

Instance Method Details

#callObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/graphable/edge_creator.rb', line 51

def call 
  return if Graphable.has_completed_edge?(@source, @target, @name)

  puts "Building #{@name} edges for #{@source.name} -> #{@target.name}"
  sources.each_slice(250) do |slice|
    Graphable.neo.batch(*slice.map { |obj|
      source_node = load_node(obj)
      relationships = []
      intermediates_for(obj).each do |intermediate_target|
         = {}
         = @metadata_proc.call(intermediate_target) if @metadata_proc
         = intermediate_target.send(:edge_metadata) if intermediate_target.respond_to?(:edge_metadata)
        target_node = load_node(intermediate_target.send(target_name)) rescue binding.pry
        next unless source_node && target_node
        relationships << [:create_relationship, @name, source_node, target_node,  || {}]
      end
      relationships
    }.flatten(1))
  end

  Graphable.completed_edge(@source, @target, @name)
end

#intermediates_for(source) ⇒ Object



80
81
82
# File 'lib/graphable/edge_creator.rb', line 80

def intermediates_for(source)
  source.send(@method)
end

#targets_for(source) ⇒ Object



74
75
76
77
78
# File 'lib/graphable/edge_creator.rb', line 74

def targets_for(source)
  res = intermediates_for(source).map(&target_name)
  res = res.to_a if res.respond_to?(:to_a)
  if res.respond_to?(:each) then res else [res] end
end