123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::Molinillo::DependencyGraph::AddVertex

Do not use. This class is for internal use only.
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/add_vertex.rb

Overview

(see #add_vertex)

Action

AddVertex

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, payload, root) ⇒ AddVertex

Initialize an action to add a vertex to a dependency graph

Parameters:

  • name (String)

    the name of the vertex

  • payload (Object)

    the payload for the vertex

  • root (Boolean)

    whether the vertex is root or not

[ GitHub ]

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

def initialize(name, payload, root)
  @name = name
  @payload = payload
  @root = root
end

Class Method Details

.action_nameSymbol

Returns:

  • (Symbol)

    The name of the action.

[ GitHub ]

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

def self.action_name
  :add_vertex
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)

    the name of the vertex

[ GitHub ]

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

attr_reader :name

#payloadObject (readonly)

Returns:

  • (Object)

    the payload for the vertex

[ GitHub ]

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

attr_reader :payload

#rootBoolean (readonly)

Returns:

  • (Boolean)

    whether the vertex is root or not

[ GitHub ]

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

attr_reader :root

Instance Method Details

#down(graph) ⇒ Void

Reverses the action on the given graph.

Parameters:

[ GitHub ]

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

def down(graph)
  if defined?(@existing_payload)
    vertex = graph.vertices[name]
    vertex.payload = @existing_payload
    vertex.root = @existing_root
  else
    graph.vertices.delete(name)
  end
end

#up(graph) ⇒ Void

Performs the action on the given graph.

Parameters:

[ GitHub ]

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

def up(graph)
  if existing = graph.vertices[name]
    @existing_payload = existing.payload
    @existing_root = existing.root
  end
  vertex = existing || Vertex.new(name, payload)
  graph.vertices[vertex.name] = vertex
  vertex.payload ||= payload
  vertex.root ||= root
  vertex
end