Module: SC::TaskManager
- Included in:
- Buildfile
- Defined in:
- lib/sproutcore/buildfile/task_manager.rb
Overview
Manages a set of tasks. Borrowed from Rake 0.8.3
Instance Attribute Summary collapse
-
#last_description ⇒ Object
(also: #last_comment)
Track the last comment made in the Rakefile.
-
#last_task_options ⇒ Object
Returns the value of attribute last_task_options.
Instance Method Summary collapse
-
#[](task_name, scopes = nil) ⇒ Object
Find a matching task for
task_name
. -
#clear ⇒ Object
Clear all tasks in this application.
- #create_rule(*args, &block) ⇒ Object
-
#current_scope ⇒ Object
Return the list of scope names currently active in the task manager.
- #define_task(task_class, *args, &block) ⇒ Object
-
#in_namespace(name) ⇒ Object
Evaluate the block in a nested namespace named
name
. - #initialize ⇒ Object
-
#intern(task_class, task_name) ⇒ Object
Lookup a task.
-
#lookup(task_name, initial_scope = nil) ⇒ Object
Lookup a task, using scope and the scope hints in the task name.
-
#resolve_args(args) ⇒ Object
Resolve the arguments for a task/rule.
-
#tasks ⇒ Object
List of all defined tasks in this application.
Instance Attribute Details
#last_description ⇒ Object Also known as: last_comment
Track the last comment made in the Rakefile.
13 14 15 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 13 def last_description @last_description end |
#last_task_options ⇒ Object
Returns the value of attribute last_task_options.
16 17 18 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 16 def @last_task_options end |
Instance Method Details
#[](task_name, scopes = nil) ⇒ Object
Find a matching task for task_name
.
53 54 55 56 57 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 53 def [](task_name, scopes=nil) task_name = task_name.to_s self.lookup(task_name, scopes) or raise "Don't know how to build task '#{task_name}'" end |
#clear ⇒ Object
Clear all tasks in this application.
127 128 129 130 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 127 def clear @tasks.clear @rules.clear end |
#create_rule(*args, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 26 def create_rule(*args, &block) pattern, arg_names, deps = resolve_args(args) pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern @rules << [pattern, deps, block] end |
#current_scope ⇒ Object
Return the list of scope names currently active in the task manager.
167 168 169 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 167 def current_scope @scope.dup end |
#define_task(task_class, *args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 32 def define_task(task_class, *args, &block) task_name, arg_names, deps = resolve_args(args) task_name = task_class.scope_name(@scope, task_name) deps = [deps] unless deps.respond_to?(:to_ary) deps = deps.collect {|d| d.to_s } task = intern(task_class, task_name) task.set_arg_names(arg_names) unless arg_names.empty? task.add_description(@last_description) task.(@last_task_options) @last_description = nil task.enhance(deps, &block) task end |
#in_namespace(name) ⇒ Object
Evaluate the block in a nested namespace named name
. Create an anonymous namespace if name
is nil.
173 174 175 176 177 178 179 180 181 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 173 def in_namespace(name) name ||= generate_name @scope.push(name) ns = NameSpace.new(self, @scope) yield(ns) ns ensure @scope.pop end |
#initialize ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 18 def initialize super @tasks = Hash.new @rules = Array.new @scope = Array.new @last_description = nil end |
#intern(task_class, task_name) ⇒ Object
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
48 49 50 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 48 def intern(task_class, task_name) @tasks[task_name.to_s] ||= task_class.new(task_name, self) end |
#lookup(task_name, initial_scope = nil) ⇒ Object
Lookup a task, using scope and the scope hints in the task name. This method performs straight lookups without trying to synthesize file tasks or rules. Special scope names (e.g. ‘^’) are recognized. If no scope argument is supplied, use the current scope. Return nil if the task cannot be found.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 137 def lookup(task_name, initial_scope=nil) initial_scope ||= @scope task_name = task_name.to_s if task_name =~ /^rake:/ scopes = [] task_name = task_name.sub(/^rake:/, '') elsif task_name =~ /^(\^+)/ scopes = initial_scope[0, initial_scope.size - $1.size] task_name = task_name.sub(/^(\^+)/, '') else scopes = initial_scope end lookup_in_scope(task_name, scopes) end |
#resolve_args(args) ⇒ Object
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
61 62 63 64 65 66 67 68 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 61 def resolve_args(args) if args.last.is_a?(Hash) deps = args.pop resolve_args_with_dependencies(args, deps) else resolve_args_without_dependencies(args) end end |
#tasks ⇒ Object
List of all defined tasks in this application.
122 123 124 |
# File 'lib/sproutcore/buildfile/task_manager.rb', line 122 def tasks @tasks.values.sort_by { |t| t.name } end |