Class: Gem::Resolver::Molinillo::DependencyGraph::Vertex
- Inherits:
-
Object
- Object
- Gem::Resolver::Molinillo::DependencyGraph::Vertex
- Defined in:
- lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb
Overview
A vertex in a Gem::Resolver::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.
-
#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 ⇒ Array<Vertex>
The vertices of #graph where ‘self` is a #descendent?.
-
#recursive_successors ⇒ Array<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.
188 189 190 191 192 193 194 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 188 def initialize(name, payload) @name = name @payload = payload @explicit_requirements = [] @outgoing_edges = [] @incoming_edges = [] end |
Instance Attribute Details
#explicit_requirements ⇒ Arrary<Object> (readonly)
Returns the explicit requirements that required this vertex.
179 180 181 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 179 def explicit_requirements @explicit_requirements end |
#incoming_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#destination.
208 209 210 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 208 def incoming_edges @incoming_edges end |
#name ⇒ String
Returns the name of the vertex.
172 173 174 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 172 def name @name end |
#outgoing_edges ⇒ Array<Edge>
Returns the edges of #graph that have ‘self` as their Edge#origin.
204 205 206 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 204 def outgoing_edges @outgoing_edges end |
#payload ⇒ Object
Returns the payload the vertex holds.
175 176 177 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 175 def payload @payload end |
#root ⇒ Boolean Also known as: root?
Returns whether the vertex is considered a root vertex.
182 183 184 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 182 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.
247 248 249 250 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 247 def ==(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?
280 281 282 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 280 def ancestor?(other) other.path_to?(self) end |
#hash ⇒ Fixnum
Returns a hash for the vertex based upon its #name.
264 265 266 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 264 def hash name.hash end |
#inspect ⇒ String
Returns a string suitable for debugging.
241 242 243 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 241 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?
271 272 273 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 271 def path_to?(other) equal?(other) || successors.any? { |v| v.path_to?(other) } end |
#predecessors ⇒ Array<Vertex>
Returns the vertices of #graph that have an edge with ‘self` as their Edge#destination.
212 213 214 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 212 def predecessors incoming_edges.map(&:origin) end |
#recursive_predecessors ⇒ Array<Vertex>
Returns the vertices of #graph where ‘self` is a #descendent?.
218 219 220 221 222 223 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 218 def recursive_predecessors vertices = predecessors vertices += vertices.map(&:recursive_predecessors).flatten(1) vertices.uniq! vertices end |
#recursive_successors ⇒ Array<Vertex>
Returns the vertices of #graph where ‘self` is an #ancestor?.
233 234 235 236 237 238 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 233 def recursive_successors vertices = successors vertices += vertices.map(&:recursive_successors).flatten(1) vertices.uniq! vertices end |
#requirements ⇒ Array<Object>
Returns all of the requirements that required this vertex.
198 199 200 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 198 def requirements incoming_edges.map(&:requirement) + explicit_requirements end |
#shallow_eql?(other) ⇒ Boolean
255 256 257 258 259 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 255 def shallow_eql?(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.
227 228 229 |
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 227 def successors outgoing_edges.map(&:destination) end |