lib/pallets/graph.rb in pallets-0.5.1 vs lib/pallets/graph.rb in pallets-0.6.0
- old
+ new
@@ -7,19 +7,23 @@
def initialize
@nodes = {}
end
def add(node, dependencies)
- @nodes[node] = dependencies
+ raise WorkflowError, "Task #{node} is already defined in this workflow. "\
+ "Use `task '#{node}', as: 'FooBar'` to define an "\
+ "alias and reuse task" if nodes.key?(node)
+
+ nodes[node] = dependencies
end
def parents(node)
- @nodes[node]
+ nodes[node]
end
def empty?
- @nodes.empty?
+ nodes.empty?
end
# Returns nodes topologically sorted, together with their order (number of
# nodes that have to be executed prior)
def sorted_with_order
@@ -35,15 +39,17 @@
end
end
private
+ attr_reader :nodes
+
def tsort_each_node(&block)
- @nodes.each_key(&block)
+ nodes.each_key(&block)
end
def tsort_each_child(node, &block)
- @nodes.fetch(node).each(&block)
+ nodes.fetch(node).each(&block)
rescue KeyError
raise WorkflowError, "Task #{node} is marked as a dependency but not defined"
end
end
end