class Gem::Resolver::Molinillo::DependencyGraph::Vertex
A vertex in a {DependencyGraph} that encapsulates a {#name} and a {#payload}
Attributes
@return [Array<Object>] the explicit requirements that required
this vertex
@return [Array<Edge>] the edges of {#graph} that have `self` as their
{Edge#destination}
@return [String] the name of the vertex
@return [Array<Edge>] the edges of {#graph} that have `self` as their
{Edge#origin}
@return [Object] the payload the vertex holds
@return [Boolean] whether the vertex is considered a root vertex
@return [Boolean] whether the vertex is considered a root vertex
Public Class Methods
Initializes a vertex with the given name and payload. @param [String] name see {#name} @param [Object] payload see {#payload}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 24 def initialize(name, payload) @name = name.frozen? ? name : name.dup.freeze @payload = payload @explicit_requirements = [] @outgoing_edges = [] @incoming_edges = [] end
Public Instance Methods
@return [Boolean] whether the two vertices are equal, determined
by a recursive traversal of each {Vertex#successors}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 83 def ==(other) return true if equal?(other) shallow_eql?(other) && successors.to_set == other.successors.to_set end
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/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 118 def ancestor?(other) other.path_to?(self) end
@return [Fixnum] a hash for the vertex based upon its {#name}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 102 def hash name.hash end
@return [String] a string suitable for debugging
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 77 def inspect "#{self.class}:#{name}(#{payload.inspect})" end
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/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 109 def path_to?(other) equal?(other) || successors.any? { |v| v.path_to?(other) } end
@return [Array<Vertex>] the vertices of {#graph} that have an edge with
`self` as their {Edge#destination}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 48 def predecessors incoming_edges.map(&:origin) end
@return [Array<Vertex>] the vertices of {#graph} where `self` is a
{#descendent?}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 54 def recursive_predecessors vertices = predecessors vertices += vertices.map(&:recursive_predecessors).flatten(1) vertices.uniq! vertices end
@return [Array<Vertex>] the vertices of {#graph} where `self` is an
{#ancestor?}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 69 def recursive_successors vertices = successors vertices += vertices.map(&:recursive_successors).flatten(1) vertices.uniq! vertices end
@return [Array<Object>] all of the requirements that required
this vertex
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 34 def requirements incoming_edges.map(&:requirement) + explicit_requirements end
@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/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 92 def shallow_eql?(other) return true if equal?(other) other && name == other.name && payload == other.payload end
@return [Array<Vertex>] the vertices of {#graph} that have an edge with
`self` as their {Edge#origin}
# File lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb, line 63 def successors outgoing_edges.map(&:destination) end