123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::Molinillo::DependencyGraph::DetachVertexNamed

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Action
Instance Chain:
self, Action
Inherits: Gem::Resolver::Molinillo::DependencyGraph::Action
Defined in: lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb

Overview

Action

DetachVertexNamed

Class Method Summary

Action - Inherited

Instance Attribute Summary

Action - Inherited

Instance Method Summary

Action - Inherited

#down

Reverses the action on the given graph.

#up

Performs the action on the given graph.

Constructor Details

.new(name) ⇒ DetachVertexNamed

Initialize an action to detach a vertex from a dependency graph

Parameters:

  • name (String)

    the name of the vertex to detach

[ GitHub ]

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

def initialize(name)
  @name = name
end

Class Method Details

.action_name

[ GitHub ]

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

def self.action_name
  :add_vertex
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)

    the name of the vertex to detach

[ GitHub ]

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

attr_reader :name

Instance Method Details

#down(graph) ⇒ Void

Reverses the action on the given graph.

Parameters:

[ GitHub ]

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

def down(graph)
  return unless @vertex
  graph.vertices[@vertex.name] = @vertex
  @vertex.outgoing_edges.each do |e|
    e.destination.incoming_edges << e
  end
  @vertex.incoming_edges.each do |e|
    e.origin.outgoing_edges << e
  end
end

#up(graph) ⇒ Void

Performs the action on the given graph.

Parameters:

[ GitHub ]

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

def up(graph)
  return [] unless @vertex = graph.vertices.delete(name)

  removed_vertices = [@vertex]
  @vertex.outgoing_edges.each do |e|
    v = e.destination
    v.incoming_edges.delete(e)
    if !v.root? && v.incoming_edges.empty?
      removed_vertices.concat graph.detach_vertex_named(v.name)
    end
  end

  @vertex.incoming_edges.each do |e|
    v = e.origin
    v.outgoing_edges.delete(e)
  end

  removed_vertices
end