Class: Graphable::ThroughEdgeCreator
Instance Method Summary
collapse
Methods inherited from EdgeCreator
#initialize, through, via
Instance Method Details
#call ⇒ Object
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 = {}
metadata = @metadata_proc.call(intermediate_target) if @metadata_proc
metadata = 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, metadata || {}]
end
relationships
}.flatten(1))
end
Graphable.completed_edge(@source, @target, @name)
end
|
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
|