Class: Bundler::Molinillo::DependencyGraph::Vertex
- Inherits:
-
Object
- Object
- Bundler::Molinillo::DependencyGraph::Vertex
- Defined in:
- lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb
Overview
A vertex in a Bundler::Molinillo::DependencyGraph that encapsulates a #name and a #payload
Instance Attribute Summary collapse
-
#explicit_requirements ⇒ Array<Object>
readonly
The explicit requirements that required this vertex.
-
#incoming_edges ⇒ Array<Edge>
The edges of #graph that have ‘self` as their Edge#destination.
-
#name ⇒ String
The name of the vertex.
-
#outgoing_edges ⇒ Array<Edge>
The edges of #graph that have ‘self` as their Edge#origin.
-
#payload ⇒ Object
The payload the vertex holds.
-
#root ⇒ Boolean
(also: #root?)
Whether the vertex is considered a root vertex.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Whether the two vertices are equal, determined by a recursive traversal of each #successors.
-
#ancestor?(other) ⇒ Boolean
(also: #is_reachable_from?)
Is there a path from ‘other` to `self` following edges in the dependency graph?.
-
#hash ⇒ Fixnum
A hash for the vertex based upon its #name.
-
#initialize(name, payload) ⇒ Vertex
constructor
Initializes a vertex with the given name and payload.
-
#inspect ⇒ String
A string suitable for debugging.
-
#path_to?(other) ⇒ Boolean
(also: #descendent?)
Is there a path from ‘self` to `other` following edges in the dependency graph?.
-
#predecessors ⇒ Array<Vertex>
The vertices of #graph that have an edge with ‘self` as their Edge#destination.
-
#recursive_predecessors ⇒ Set<Vertex>
The vertices of #graph where ‘self` is a #descendent?.
-
#recursive_successors ⇒ Set<Vertex>
The vertices of #graph where ‘self` is an #ancestor?.
-
#requirements ⇒ Array<Object>
All of the requirements that required this vertex.
- #shallow_eql?(other) ⇒ Boolean
-
#successors ⇒ Array<Vertex>
The vertices of #graph that have an edge with ‘self` as their Edge#origin.
Constructor Details
#initialize(name, payload) ⇒ Vertex
Initializes a vertex with the given name and payload.
25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#explicit_requirements ⇒ Array<Object> (readonly)
Returns the explicit requirements that required this vertex.
16 17 18 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 16 def explicit_requirements @explicit_requirements end |
#incoming_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#destination.
45 46 47 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 45 def incoming_edges @incoming_edges end |
#name ⇒ String
Returns the name of the vertex.
9 10 11 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 9 def name @name end |
#outgoing_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#origin.
41 42 43 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 41 def outgoing_edges @outgoing_edges end |
#payload ⇒ Object
Returns the payload the vertex holds.
12 13 14 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 12 def payload @payload end |
#root ⇒ Boolean Also known as: root?
Returns whether the vertex is considered a root vertex.
19 20 21 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 19 def root @root end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns whether the two vertices are equal, determined by a recursive traversal of each #successors.
106 107 108 109 110 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 106 def ==(other) return true if equal?(other) shallow_eql?(other) && successors.to_set == other.successors.to_set end |
#ancestor?(other) ⇒ Boolean Also known as: is_reachable_from?
Is there a path from ‘other` to `self` following edges in the dependency graph?
151 152 153 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 151 def ancestor?(other) other.path_to?(self) end |
#hash ⇒ Fixnum
Returns a hash for the vertex based upon its #name.
125 126 127 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 125 def hash name.hash end |
#inspect ⇒ String
Returns a string suitable for debugging.
100 101 102 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 100 def inspect "#{self.class}:#{name}(#{payload.inspect})" end |
#path_to?(other) ⇒ Boolean Also known as: descendent?
Is there a path from ‘self` to `other` following edges in the dependency graph?
132 133 134 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 132 def path_to?(other) _path_to?(other) end |
#predecessors ⇒ Array<Vertex>
Returns the vertices of #graph that have an edge with ‘self` as their Edge#destination.
49 50 51 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 49 def predecessors incoming_edges.map(&:origin) end |
#recursive_predecessors ⇒ Set<Vertex>
Returns the vertices of #graph where ‘self` is a #descendent?.
55 56 57 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 55 def recursive_predecessors _recursive_predecessors end |
#recursive_successors ⇒ Set<Vertex>
Returns the vertices of #graph where ‘self` is an #ancestor?.
81 82 83 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 81 def recursive_successors _recursive_successors end |
#requirements ⇒ Array<Object>
Returns all of the requirements that required this vertex.
35 36 37 |
# 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) ⇒ Boolean
115 116 117 118 119 120 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 115 def shallow_eql?(other) return true if equal?(other) other && name == other.name && payload == other.payload end |
#successors ⇒ Array<Vertex>
Returns the vertices of #graph that have an edge with ‘self` as their Edge#origin.
75 76 77 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 75 def successors outgoing_edges.map(&:destination) end |