lib/ratch/taskable.rb in ratch-0.2.2 vs lib/ratch/taskable.rb in ratch-0.2.3
- old
+ new
@@ -1,14 +1,37 @@
+# TITLE:
+#
+# Taskable
+#
+# COPYING:
+#
+# Copyright (c) 2007 Psi T Corp.
+#
+# This file is part of the ProUtils' Ratch program.
+#
+# Ratch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ratch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ratch. If not, see <http://www.gnu.org/licenses/>.
+
module Ratch
# = Taskable Mixin
#
module Taskable
# Reference task manager.
def task_manager
- @task_manager ||= TaskManager.new
+ @task_manager ||= TaskManager.new(self)
end
# Define a main task.
def main(name, &block)
name, deps, block = *parse_task_dependencies(name, &block)
@@ -44,12 +67,14 @@
# = TaskManager Class
#
class TaskManager
attr :main
attr :tasks
+ attr :runspace
- def initialize
+ def initialize(runspace)
+ @runspace = runspace
@main = nil
@tasks = {}
end
def define_main(name=nil, *depend, &block)
@@ -76,34 +101,45 @@
# Prepare plan, checking for circular dependencies.
def plan(name, list=[])
if list.include?(name)
raise "Circular dependency #{name}."
end
- task = @tasks[name]
- task.preqs.each do |need|
- need = need.to_s
- next if list.include?(need)
- #@tasks[need].plan(need, list)
- plan(need, list)
+ if task = @tasks[name]
+ task.needs.each do |need|
+ need = need.to_s
+ next if list.include?(need)
+ #@tasks[need].plan(need, list)
+ plan(need, list)
+ end
+ list << task.name
+ else
+ if fname = runspace.batch?(name) # TODO THIS TIES TASKS INTO BATCH, BETTER WAY?
+ task = Task.new(name) do
+ runspace.batch(fname)
+ end
+ @tasks[name] = task
+ list << task.name
+ else
+ abort "no task -- #{name}"
+ end
end
- list << task.name
return list
end
end
# = Task class
#
class Task
attr :name
- attr :preqs
+ attr :needs
attr :action
#
- def initialize(name, *preqs, &action)
+ def initialize(name, *needs, &action)
@name = name.to_s
- @preqs = preqs
+ @needs = needs
@action = action
end
#
def call