Class: Bundler::Molinillo::DependencyGraph::Vertex

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(graph, name, payload) ⇒ Vertex

Returns a new instance of Vertex.

Parameters:



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

Returns the explicit requirements that required this vertex.

Returns:

  • (Arrary<Object>)

    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

#graphDependencyGraph

Returns the graph this vertex is a node of.

Returns:



162
163
164
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 162

def graph
  @graph
end

#nameString

Returns the name of the vertex.

Returns:

  • (String)

    the name of the vertex



165
166
167
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 165

def name
  @name
end

#payloadObject

Returns the payload the vertex holds.

Returns:

  • (Object)

    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.

Returns:

  • (Boolean)

    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?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #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

#hashFixnum

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

Returns:

  • (Fixnum)

    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_edgesArray<Edge>

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

Returns:



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

#inspectString

Returns a string suitable for debugging.

Returns:

  • (String)

    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_edgesArray<Edge>

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

Returns:



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?

Returns:

  • (Boolean)

    true iff there is a path following edges within this #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

#predecessorsSet<Vertex>

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

Returns:



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_successorsSet<Vertex>

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

Returns:



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

#requirementsArray<Object>

Returns all of the requirements that required this vertex.

Returns:

  • (Array<Object>)

    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

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

Returns:

  • (Boolean)

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



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

#successorsSet<Vertex>

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

Returns:



210
211
212
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb', line 210

def successors
  outgoing_edges.map(&:destination).to_set
end