class Bundler::Molinillo::DependencyGraph::Vertex

A vertex in a {DependencyGraph} that encapsulates a {#name} and a {#payload}

Attributes

explicit_requirements[R]

@return [Array<Object>] the explicit requirements that required

this vertex
incoming_edges[RW]

@return [Array<Edge>] the edges of {#graph} that have `self` as their

{Edge#destination}
name[RW]

@return [String] the name of the vertex

outgoing_edges[RW]

@return [Array<Edge>] the edges of {#graph} that have `self` as their

{Edge#origin}
payload[RW]

@return [Object] the payload the vertex holds

root[RW]

@return [Boolean] whether the vertex is considered a root vertex

root?[RW]

@return [Boolean] whether the vertex is considered a root vertex

Public Class Methods

new(name, payload) click to toggle source

Initializes a vertex with the given name and payload. @param [String] name see {#name} @param [Object] payload see {#payload}

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 25
def initialize(name, payload)
  @name = name.frozen? ? name : name.dup.freeze
  @payload = payload
  @explicit_requirements = []
  @outgoing_edges = []
  @incoming_edges = []
end

Public Instance Methods

==(other) click to toggle source

@return [Boolean] whether the two vertices are equal, determined

by a recursive traversal of each {Vertex#successors}
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 84
def ==(other)
  return true if equal?(other)
  shallow_eql?(other) &&
    successors.to_set == other.successors.to_set
end
Also aliased as: eql?
ancestor?(other) click to toggle source

Is there a path from `other` to `self` following edges in the dependency graph? @return true iff there is a path following edges within this {#graph}

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 129
def ancestor?(other)
  other.path_to?(self)
end
Also aliased as: is_reachable_from?
descendent?(other)
Alias for: path_to?
eql?(other)
Alias for: ==
hash() click to toggle source

@return [Fixnum] a hash for the vertex based upon its {#name}

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 103
def hash
  name.hash
end
inspect() click to toggle source

@return [String] a string suitable for debugging

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 78
def inspect
  "#{self.class}:#{name}(#{payload.inspect})"
end
is_reachable_from?(other)
Alias for: ancestor?
path_to?(other) click to toggle source

Is there a path from `self` to `other` following edges in the dependency graph? @return true iff there is a path following edges within this {#graph}

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 110
def path_to?(other)
  _path_to?(other)
end
Also aliased as: descendent?
predecessors() click to toggle source

@return [Array<Vertex>] the vertices of {#graph} that have an edge with

`self` as their {Edge#destination}
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 49
def predecessors
  incoming_edges.map(&:origin)
end
recursive_predecessors() click to toggle source

@return [Array<Vertex>] the vertices of {#graph} where `self` is a

{#descendent?}
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 55
def recursive_predecessors
  vertices = predecessors
  vertices += Compatibility.flat_map(vertices, &:recursive_predecessors)
  vertices.uniq!
  vertices
end
recursive_successors() click to toggle source

@return [Array<Vertex>] the vertices of {#graph} where `self` is an

{#ancestor?}
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 70
def recursive_successors
  vertices = successors
  vertices += Compatibility.flat_map(vertices, &:recursive_successors)
  vertices.uniq!
  vertices
end
requirements() click to toggle source

@return [Array<Object>] all of the requirements that required

this vertex
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 35
def requirements
  (incoming_edges.map(&:requirement) + explicit_requirements).uniq
end
shallow_eql?(other) click to toggle source

@param [Vertex] other the other vertex to compare to @return [Boolean] whether the two vertices are equal, determined

solely by {#name} and {#payload} equality
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 93
def shallow_eql?(other)
  return true if equal?(other)
  other &&
    name == other.name &&
    payload == other.payload
end
successors() click to toggle source

@return [Array<Vertex>] the vertices of {#graph} that have an edge with

`self` as their {Edge#origin}
# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 64
def successors
  outgoing_edges.map(&:destination)
end

Protected Instance Methods

_path_to?(other, visited = Set.new) click to toggle source

@param [Vertex] other the vertex to check if there's a path to @param [Set<Vertex>] visited the vertices of {#graph} that have been visited @return [Boolean] whether there is a path to `other` from `self`

# File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 119
def _path_to?(other, visited = Set.new)
  return false unless visited.add?(self)
  return true if equal?(other)
  successors.any? { |v| v._path_to?(other, visited) }
end