lib/attr/gather/workflow/task_graph.rb in attr-gather-1.1.3 vs lib/attr/gather/workflow/task_graph.rb in attr-gather-1.2.0
- old
+ new
@@ -18,11 +18,13 @@
def initialize(tasks: [])
@tasks_hash = {}
tasks.each { |t| self << t }
end
- def <<(task)
+ def <<(hash)
+ name, depends_on = hash.values_at :name, :depends_on
+ task = build_task(name, depends_on)
validate_for_insert!(task)
registered_tasks.each do |t|
tasks_hash[t] << task if t.depends_on?(task)
tasks_hash[t].uniq!
@@ -66,10 +68,20 @@
preview ? serializer.preview : serializer.to_dot
end
private
+ def build_task(name, depends_on)
+ deps = depends_on.map do |dep_name|
+ registered_tasks.find do |task|
+ task.name == dep_name
+ end
+ end
+
+ Task.new(name: name, depends_on: deps)
+ end
+
def tsort_each_child(node, &blk)
to_h[node].each(&blk)
end
def tsort_each_node(&blk)
@@ -97,10 +109,10 @@
def registered_tasks
tasks_hash.keys
end
def depended_on_tasks_exist?(task)
- task.depends_on.all? { |t| registered_tasks.map(&:name).include?(t) }
+ task.depends_on.all? { |t| registered_tasks.include?(t) }
end
end
end
end
end