Class: Molinillo::DependencyGraph::Log
- Inherits:
-
Object
- Object
- Molinillo::DependencyGraph::Log
- Extended by:
- Enumerable
- Defined in:
- lib/molinillo/dependency_graph/log.rb
Overview
A log for dependency graph actions
Instance Method Summary collapse
-
#add_edge_no_circular(graph, origin, destination, requirement) ⇒ Edge
Adds a new Edge to the dependency graph without checking for circularity.
-
#add_vertex(graph, name, payload, root) ⇒ Vertex
Adds a vertex with the given name, or updates the existing one.
-
#detach_vertex_named(graph, name) ⇒ void
Detaches the #vertex_named ‘name` Vertex from the graph, recursively removing any non-root vertices that were orphaned in the process
-
#initialize ⇒ Log
constructor
Initializes an empty log.
-
#pop!(graph) ⇒ Action
Pops the most recent action from the log and undoes the action.
-
#rewind_to(graph, tag) ⇒ Void
Rewinds the graph to the state tagged as ‘tag`
-
#set_payload(graph, name, payload) ⇒ Void
Sets the payload of the vertex with the given name
-
#tag(graph, tag) ⇒ Void
Tags the current state of the dependency as the given tag
Constructor Details
#initialize ⇒ Log
Initializes an empty log
13 14 15 |
# File 'lib/molinillo/dependency_graph/log.rb', line 13 def initialize @current_action = @first_action = nil end |
Instance Method Details
#add_edge_no_circular(graph, origin, destination, requirement) ⇒ Edge
39 40 41 |
# File 'lib/molinillo/dependency_graph/log.rb', line 39 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
29 30 31 |
# File 'lib/molinillo/dependency_graph/log.rb', line 29 def add_vertex(graph, name, payload, root) push_action(graph, AddVertex.new(name, payload, root)) end |
#detach_vertex_named(graph, name) ⇒ void
This method returns an undefined value.
34 35 36 |
# File 'lib/molinillo/dependency_graph/log.rb', line 34 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
51 52 53 54 55 56 57 58 |
# File 'lib/molinillo/dependency_graph/log.rb', line 51 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
91 92 93 94 95 96 97 |
# File 'lib/molinillo/dependency_graph/log.rb', line 91 def rewind_to(graph, tag) loop do action = pop!(graph) raise "No tag #{tag.inspect} found" unless action break if action.class.name == :tag && action.tag == tag end end |
#set_payload(graph, name, payload) ⇒ Void
44 45 46 |
# File 'lib/molinillo/dependency_graph/log.rb', line 44 def set_payload(graph, name, payload) push_action(graph, SetPayload.new(name, payload)) end |
#tag(graph, tag) ⇒ Void
24 25 26 |
# File 'lib/molinillo/dependency_graph/log.rb', line 24 def tag(graph, tag) push_action(graph, Tag.new(tag)) end |