123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, payload) ⇒ Vertex

Initializes a vertex with the given name and payload.

Parameters:

[ GitHub ]

  
# 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_requirementsArrary<Object> (readonly)

Returns:

  • (Arrary<Object>)

    the explicit requirements that required this vertex

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 179

attr_reader :explicit_requirements

#incoming_edgesArray<Edge> (rw)

Returns:

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 208

attr_accessor :incoming_edges

#nameString (rw)

Returns:

  • (String)

    the name of the vertex

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 172

attr_accessor :name

#outgoing_edgesArray<Edge> (rw)

Returns:

  • (Array<Edge>)

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

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 204

attr_accessor :outgoing_edges

#payloadObject (rw)

Returns:

  • (Object)

    the payload the vertex holds

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 175

attr_accessor :payload

#root? (rw)

Alias for #root.

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 183

alias_method :root?, :root

Instance Method Details

#==(other) ⇒ Boolean Also known as: #eql?

Returns:

  • (Boolean)

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

[ GitHub ]

  
# 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?

Returns:

  • (Boolean)

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

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 280

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

#descendent?(other)

Alias for #path_to?.

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 275

alias_method :descendent?, :path_to?

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 261

alias_method :eql?, :==

#hashFixnum

Returns:

  • (Fixnum)

    a hash for the vertex based upon its #name

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 264

def hash
  name.hash
end

#inspectString

Returns:

  • (String)

    a string suitable for debugging

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 241

def inspect
  "#{self.class}:#{name}(#{payload.inspect})"
end

#is_reachable_from?(other)

Alias for #ancestor?.

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 284

alias_method :is_reachable_from?, :ancestor?

#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

[ GitHub ]

  
# 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

#predecessorsArray<Vertex>

Returns:

  • (Array<Vertex>)

    the vertices of #graph that have an edge with self as their Edge#destination

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 212

def predecessors
  incoming_edges.map(&:origin)
end

#recursive_predecessorsArray<Vertex>

Returns:

  • (Array<Vertex>)

    the vertices of #graph where self is a #descendent?

[ GitHub ]

  
# 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_successorsArray<Vertex>

Returns:

  • (Array<Vertex>)

    the vertices of #graph where self is an #ancestor?

[ GitHub ]

  
# 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

#requirementsArray<Object>

Returns:

  • (Array<Object>)

    all of the requirements that required this vertex

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 198

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

#rootBoolean (rw) Also known as: #root?

Returns:

  • (Boolean)

    whether the vertex is considered a root vertex

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 182

attr_accessor :root

#shallow_eql?(other) ⇒ Boolean

Parameters:

  • other (Vertex)

    the other vertex to compare to

Returns:

  • (Boolean)

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

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 255

def shallow_eql?(other)
  other &&
    name == other.name &&
    payload == other.payload
end

#successorsArray<Vertex>

Returns:

  • (Array<Vertex>)

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

[ GitHub ]

  
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb', line 227

def successors
  outgoing_edges.map(&:destination)
end