Class: Bundler::Molinillo::DependencyGraph::Log

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/bundler/vendor/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


15
16
17
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 15

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


41
42
43
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 41

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`


31
32
33
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 31

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)

51
52
53
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 51

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


36
37
38
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 36

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


63
64
65
66
67
68
69
70
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 63

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)

103
104
105
106
107
108
109
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 103

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)

56
57
58
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 56

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)

26
27
28
# File 'lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb', line 26

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