123456789_123456789_123456789_123456789_123456789_

Class: Gem::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::Molinillo::DependencyGraph::Action
Defined in: lib/rubygems/vendor/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/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 55

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/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 12

def self.action_name
  :add_vertex
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)

    the name of the vertex

[ GitHub ]

  
# File 'lib/rubygems/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 43

attr_reader :name

#payloadObject (readonly)

Returns:

  • (Object)

    the payload for the vertex

[ GitHub ]

  
# File 'lib/rubygems/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 46

attr_reader :payload

#rootBoolean (readonly)

Returns:

  • (Boolean)

    whether the vertex is root or not

[ GitHub ]

  
# File 'lib/rubygems/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 49

attr_reader :root

Instance Method Details

#down(graph) ⇒ Void

Reverses the action on the given graph.

Parameters:

[ GitHub ]

  
# File 'lib/rubygems/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 30

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/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb', line 17

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