Class: Gem::Resolver::Molinillo::DependencyGraph::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb

Overview

A vertex in a Gem::Resolver::Molinillo::DependencyGraph that encapsulates a #name and a #payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, payload) ⇒ Vertex

Initializes a vertex with the given name and payload.

Parameters:



24
25
26
27
28
29
30
# 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

Instance Attribute Details

#explicit_requirementsArray<Object> (readonly)

Returns the explicit requirements that required this vertex.

Returns:

  • (Array<Object>)

    the explicit requirements that required this vertex



15
16
17
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 15

def explicit_requirements
  @explicit_requirements
end

#incoming_edgesArray<Edge>

Returns the edges of #graph that have ‘self` as their Edge#destination.

Returns:



44
45
46
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 44

def incoming_edges
  @incoming_edges
end

#nameString

Returns the name of the vertex.

Returns:

  • (String)

    the name of the vertex



8
9
10
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 8

def name
  @name
end

#outgoing_edgesArray<Edge>

Returns the edges of #graph that have ‘self` as their Edge#origin.

Returns:

  • (Array<Edge>)

    the edges of #graph that have ‘self` as their Edge#origin



40
41
42
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 40

def outgoing_edges
  @outgoing_edges
end

#payloadObject

Returns the payload the vertex holds.

Returns:

  • (Object)

    the payload the vertex holds



11
12
13
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 11

def payload
  @payload
end

#rootBoolean Also known as: root?

Returns whether the vertex is considered a root vertex.

Returns:

  • (Boolean)

    whether the vertex is considered a root vertex



18
19
20
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 18

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.

Returns:

  • (Boolean)

    whether the two vertices are equal, determined by a recursive traversal of each #successors



83
84
85
86
87
# 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

#ancestor?(other) ⇒ Boolean Also known as: is_reachable_from?

Is there a path from ‘other` to `self` following edges in the dependency graph?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #graph



118
119
120
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 118

def ancestor?(other)
  other.path_to?(self)
end

#hashFixnum

Returns a hash for the vertex based upon its #name.

Returns:

  • (Fixnum)

    a hash for the vertex based upon its #name



102
103
104
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 102

def hash
  name.hash
end

#inspectString

Returns a string suitable for debugging.

Returns:

  • (String)

    a string suitable for debugging



77
78
79
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 77

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?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #graph



109
110
111
# 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

#predecessorsArray<Vertex>

Returns the vertices of #graph that have an edge with ‘self` as their Edge#destination.

Returns:



48
49
50
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 48

def predecessors
  incoming_edges.map(&:origin)
end

#recursive_predecessorsArray<Vertex>

Returns the vertices of #graph where ‘self` is a #descendent?.

Returns:



54
55
56
57
58
59
# 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

#recursive_successorsArray<Vertex>

Returns the vertices of #graph where ‘self` is an #ancestor?.

Returns:



69
70
71
72
73
74
# 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

#requirementsArray<Object>

Returns all of the requirements that required this vertex.

Returns:

  • (Array<Object>)

    all of the requirements that required this vertex



34
35
36
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 34

def requirements
  incoming_edges.map(&:requirement) + explicit_requirements
end

#shallow_eql?(other) ⇒ Boolean

Returns whether the two vertices are equal, determined solely by #name and #payload equality.

Parameters:

  • other (Vertex)

    the other vertex to compare to

Returns:

  • (Boolean)

    whether the two vertices are equal, determined solely by #name and #payload equality



92
93
94
95
96
97
# 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

#successorsArray<Vertex>

Returns the vertices of #graph that have an edge with ‘self` as their Edge#origin.

Returns:

  • (Array<Vertex>)

    the vertices of #graph that have an edge with ‘self` as their Edge#origin



63
64
65
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb', line 63

def successors
  outgoing_edges.map(&:destination)
end