Class: Gem::Resolver::Molinillo::DependencyGraph::Log

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb

Overview

A log for dependency graph actions

Instance Method Summary collapse

Constructor Details

#initializeLog

Initializes an empty log


14
15
16
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 14

def initialize
  @current_action = @first_action = nil
end

Instance Method Details

#add_edge_no_circular(graph, origin, destination, requirement) ⇒ Edge

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • origin (Vertex)
  • destination (Vertex)
  • requirement (Object)

    the requirement that this edge represents

Returns:

  • (Edge)

    the added edge


40
41
42
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 40

def add_edge_no_circular(graph, origin, destination, requirement)
  push_action(graph, AddEdgeNoCircular.new(origin, destination, requirement))
end

#add_vertex(graph, name, payload, root) ⇒ Vertex

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • name (String)
  • payload (Object)

Returns:

  • (Vertex)

    the vertex that was added to `self`


30
31
32
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 30

def add_vertex(graph, name, payload, root)
  push_action(graph, AddVertex.new(name, payload, root))
end

#delete_edge(graph, origin_name, destination_name, requirement) ⇒ Void

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • origin_name (String)
  • destination_name (String)
  • requirement (Object)

Returns:

  • (Void)

50
51
52
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 50

def delete_edge(graph, origin_name, destination_name, requirement)
  push_action(graph, DeleteEdge.new(origin_name, destination_name, requirement))
end

#detach_vertex_named(graph, name) ⇒ Array<Vertex>

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • name (String)

Returns:

  • (Array<Vertex>)

    the vertices which have been detached


35
36
37
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 35

def detach_vertex_named(graph, name)
  push_action(graph, DetachVertexNamed.new(name))
end

#pop!(graph) ⇒ Action

Pops the most recent action from the log and undoes the action

Parameters:

Returns:

  • (Action)

    the action that was popped off the log


62
63
64
65
66
67
68
69
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 62

def pop!(graph)
  return unless action = @current_action
  unless @current_action = action.previous
    @first_action = nil
  end
  action.down(graph)
  action
end

#rewind_to(graph, tag) ⇒ Void

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • tag (Object)

    the tag to rewind to

Returns:

  • (Void)

102
103
104
105
106
107
108
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 102

def rewind_to(graph, tag)
  loop do
    action = pop!(graph)
    raise "No tag #{tag.inspect} found" unless action
    break if action.class.action_name == :tag && action.tag == tag
  end
end

#set_payload(graph, name, payload) ⇒ Void

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • name (String)

    the name of the vertex

  • payload (Object)

    the payload

Returns:

  • (Void)

55
56
57
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 55

def set_payload(graph, name, payload)
  push_action(graph, SetPayload.new(name, payload))
end

#tag(graph, tag) ⇒ Void

Parameters:

  • graph (Graph)

    the graph to perform the action on

  • tag (Object)

    an opaque tag for the current state of the graph

Returns:

  • (Void)

25
26
27
# File 'lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb', line 25

def tag(graph, tag)
  push_action(graph, Tag.new(tag))
end