class Bundler::Molinillo::DependencyGraph

A directed acyclic graph that is tuned to hold named dependencies

def self.tsort(vertices)

Returns:
  • (Array) - The sorted vertices.

Parameters:
  • vertices (Enumerable) -- the vertices to be sorted, which must
def self.tsort(vertices)
  TSort.tsort(
    lambda { |b| vertices.each(&b) },
    lambda { |v, &b| (v.successors & vertices).each(&b) }
  )
end

def ==(other)

Returns:
  • (Boolean) - whether the two dependency graphs are equal, determined
def ==(other)
  return false unless other
  vertices.each do |name, vertex|
    other_vertex = other.vertex_named(name)
    return false unless other_vertex
    return false unless other_vertex.successors.map(&:name).to_set == vertex.successors.map(&:name).to_set
  end
end

def add_child_vertex(name, payload, parent_names, requirement)

Returns:
  • (void) -

Parameters:
  • requirement (Object) -- the requirement that is requiring the child
  • parent_names (Array) --
  • payload (Object) --
  • name (String) --
def add_child_vertex(name, payload, parent_names, requirement)
  vertex = add_vertex(name, payload)
  parent_names.each do |parent_name|
    unless parent_name
      vertex.root = true
      next
    end
    parent_node = vertex_named(parent_name)
    add_edge(parent_node, vertex, requirement)
  end
  vertex
end

def add_edge(origin, destination, requirement)

Returns:
  • (Edge) - the added edge

Parameters:
  • requirement (Object) -- the requirement that this edge represents
  • destination (Vertex) --
  • origin (Vertex) --
def add_edge(origin, destination, requirement)
  if destination.path_to?(origin)
    raise CircularDependencyError.new([origin, destination])
  end
  add_edge_no_circular(origin, destination, requirement)
end

def add_edge_no_circular(origin, destination, requirement)

def add_edge_no_circular(origin, destination, requirement)
  edge = Edge.new(origin, destination, requirement)
  origin.outgoing_edges << edge
  destination.incoming_edges << edge
  edge
end

def add_vertex(name, payload, root = false)

Returns:
  • (Vertex) - the vertex that was added to `self`

Parameters:
  • payload (Object) --
  • name (String) --
def add_vertex(name, payload, root = false)
  vertex = vertices[name] ||= Vertex.new(name, payload)
  vertex.payload ||= payload
  vertex.root ||= root
  vertex
end

def detach_vertex_named(name)

Returns:
  • (void) -

Parameters:
  • name (String) --
def detach_vertex_named(name)
  return unless vertex = vertices.delete(name)
  vertex.outgoing_edges.each do |e|
    v = e.destination
    v.incoming_edges.delete(e)
    detach_vertex_named(v.name) unless v.root? || v.predecessors.any?
  end
end

def each

Returns:
  • (Array) - The graph's vertices.
def each
  vertices.values.each { |v| yield v }
end

def initialize

def initialize
  @vertices = {}
end

def initialize_copy(other)

are properly copied.
Initializes a copy of a {DependencyGraph}, ensuring that all {#vertices}
def initialize_copy(other)
  super
  @vertices = {}
  traverse = lambda do |new_v, old_v|
    return if new_v.outgoing_edges.size == old_v.outgoing_edges.size
    old_v.outgoing_edges.each do |edge|
      destination = add_vertex(edge.destination.name, edge.destination.payload)
      add_edge_no_circular(new_v, destination, edge.requirement)
      traverse.call(destination, edge.destination)
    end
  end
  other.vertices.each do |name, vertex|
    new_vertex = add_vertex(name, vertex.payload, vertex.root?)
    new_vertex.explicit_requirements.replace(vertex.explicit_requirements)
    traverse.call(new_vertex, vertex)
  end
end

def inspect

Returns:
  • (String) - a string suitable for debugging
def inspect
  "#{self.class}:#{vertices.values.inspect}"
end

def root_vertex_named(name)

Returns:
  • (Vertex, nil) - the root vertex with the given name

Parameters:
  • name (String) --
def root_vertex_named(name)
  vertex = vertex_named(name)
  vertex if vertex && vertex.root?
end

def tsort_each_child(vertex, &block)

def tsort_each_child(vertex, &block)
  vertex.successors.each(&block)
end

def vertex_named(name)

Returns:
  • (Vertex, nil) - the vertex with the given name

Parameters:
  • name (String) --
def vertex_named(name)
  vertices[name]
end