fixup_swapped_children(vertex)
private
Ensures there are no orphaned successors to the given {vertex}. @param
[DependencyGraph::Vertex] vertex the vertex to fix up. @return [void]
Show source
def fixup_swapped_children(vertex)
payload = vertex.payload
deps = dependencies_for(payload).group_by(&method(:name_for))
vertex.outgoing_edges.each do |outgoing_edge|
requirement = outgoing_edge.requirement
parent_index = @parents_of[requirement].last
succ = outgoing_edge.destination
matching_deps = Array(deps[succ.name])
dep_matched = matching_deps.include?(requirement)
if parent_index && states[parent_index].name == name
@parents_of[requirement].push(states.size - 1)
end
if matching_deps.empty? && !succ.root? && succ.predecessors.to_a == [vertex]
debug(depth) { "Removing orphaned spec #{succ.name} after swapping #{name}" }
succ.requirements.each { |r| @parents_of.delete(r) }
removed_names = activated.detach_vertex_named(succ.name).map(&:name)
requirements.delete_if do |r|
removed_names.include?(name_for(r))
end
elsif !dep_matched
debug(depth) { "Removing orphaned dependency #{requirement} after swapping #{name}" }
@parents_of[requirement].push(states.size - 1) if @parents_of[requirement].empty?
activated.delete_edge(outgoing_edge)
requirements.delete(requirement)
end
end
end