Class: Bundler::Molinillo::DependencyGraph::Vertex
- Inherits:
-
Object
- Object
- Bundler::Molinillo::DependencyGraph::Vertex
- Defined in:
- lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb
Overview
A vertex in a Bundler::Molinillo::DependencyGraph that encapsulates a #name and a #payload
Instance Attribute Summary collapse
-
#explicit_requirements ⇒ Arrary<Object>
readonly
The explicit requirements that required this vertex.
-
#graph ⇒ DependencyGraph
The graph this vertex is a node of.
-
#name ⇒ String
The name of the vertex.
-
#payload ⇒ Object
The payload the vertex holds.
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.
-
#incoming_edges ⇒ Array<Edge>
The edges of #graph that have ‘self` as their Edge#destination.
-
#initialize(graph, name, payload) ⇒ Vertex
constructor
A new instance of Vertex.
-
#inspect ⇒ String
A string suitable for debugging.
-
#outgoing_edges ⇒ Array<Edge>
The edges of #graph that have ‘self` as their Edge#origin.
-
#path_to?(other) ⇒ Boolean
(also: #descendent?)
Is there a path from ‘self` to `other` following edges in the dependency graph?.
-
#predecessors ⇒ Set<Vertex>
The vertices of #graph that have an edge with ‘self` as their Edge#destination.
-
#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 ⇒ Set<Vertex>
The vertices of #graph that have an edge with ‘self` as their Edge#origin.
Constructor Details
#initialize(graph, name, payload) ⇒ Vertex
Returns a new instance of Vertex.
177 178 179 180 181 182 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 177 def initialize(graph, name, payload) @graph = graph @name = name @payload = payload @explicit_requirements = [] end |
Instance Attribute Details
#explicit_requirements ⇒ Arrary<Object> (readonly)
Returns the explicit requirements that required this vertex.
172 173 174 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 172 def explicit_requirements @explicit_requirements end |
#graph ⇒ DependencyGraph
Returns the graph this vertex is a node of.
162 163 164 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 162 def graph @graph end |
#name ⇒ String
Returns the name of the vertex.
165 166 167 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 165 def name @name end |
#payload ⇒ Object
Returns the payload the vertex holds.
168 169 170 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 168 def payload @payload 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.
227 228 229 230 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 227 def ==(other) shallow_eql?(other) && successors == other.successors end |
#ancestor?(other) ⇒ Boolean Also known as: is_reachable_from?
Is there a path from ‘other` to `self` following edges in the dependency graph?
259 260 261 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 259 def ancestor?(other) predecessors.include?(other) || predecessors.any? { |v| v.ancestor?(other) } end |
#hash ⇒ Fixnum
Returns a hash for the vertex based upon its #name.
243 244 245 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 243 def hash name.hash end |
#incoming_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#destination.
198 199 200 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 198 def incoming_edges graph.edges.select { |e| e.destination.shallow_eql?(self) } end |
#inspect ⇒ String
Returns a string suitable for debugging.
221 222 223 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 221 def inspect "#{self.class}:#{name}(#{payload.inspect})" end |
#outgoing_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#origin.
192 193 194 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 192 def outgoing_edges graph.edges.select { |e| e.origin.shallow_eql?(self) } end |
#path_to?(other) ⇒ Boolean Also known as: descendent?
Is there a path from ‘self` to `other` following edges in the dependency graph?
250 251 252 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 250 def path_to?(other) successors.include?(other) || successors.any? { |v| v.path_to?(other) } end |
#predecessors ⇒ Set<Vertex>
Returns the vertices of #graph that have an edge with ‘self` as their Edge#destination.
204 205 206 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 204 def predecessors incoming_edges.map(&:origin).to_set end |
#recursive_successors ⇒ Set<Vertex>
Returns the vertices of #graph where ‘self` is an #ancestor?.
216 217 218 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 216 def recursive_successors successors + successors.map(&:recursive_successors).reduce(Set.new, &:+) end |
#requirements ⇒ Array<Object>
Returns all of the requirements that required this vertex.
186 187 188 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 186 def requirements incoming_edges.map(&:requirements).flatten + explicit_requirements end |
#shallow_eql?(other) ⇒ Boolean
234 235 236 237 238 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 234 def shallow_eql?(other) other && name == other.name && payload == other.payload end |
#successors ⇒ Set<Vertex>
Returns the vertices of #graph that have an edge with ‘self` as their Edge#origin.
210 211 212 |
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 210 def successors outgoing_edges.map(&:destination).to_set end |