Module
Rake::TaskManager
In: lib/rake/task_manager.rb

The TaskManager module is a mixin for managing tasks.

Methods

[], clear, create_rule, current_scope, define_task, enhance_with_matching_rule, in_namespace, intern, lookup, new, resolve_args, synthesize_file_task, tasks, tasks_in_scope,
Attributes

 [RW]  last_description Track the last comment made in the Rakefile.
 [RW]  record_task_metadata
Public Class methods
new()
    # File lib/rake/task_manager.rb, line 9
 9:     def initialize
10:       super
11:       @tasks = Hash.new
12:       @rules = Array.new
13:       @scope = Array.new
14:       @last_description = nil
15:     end
Public Instance methods
[](task_name, scopes=nil)

Find a matching task for task_name.

    # File lib/rake/task_manager.rb, line 44
44:     def [](task_name, scopes=nil)
45:       task_name = task_name.to_s
46:       self.lookup(task_name, scopes) or
47:         enhance_with_matching_rule(task_name) or
48:         synthesize_file_task(task_name) or
49:         fail "Don't know how to build task '#{task_name}'"
50:     end
clear()

Clear all tasks in this application.

     # File lib/rake/task_manager.rb, line 153
153:     def clear
154:       @tasks.clear
155:       @rules.clear
156:     end
create_rule(*args, &block)
    # File lib/rake/task_manager.rb, line 17
17:     def create_rule(*args, &block)
18:       pattern, arg_names, deps = resolve_args(args)
19:       pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
20:       @rules << [pattern, deps, block]
21:     end
current_scope()

Return the list of scope names currently active in the task manager.

     # File lib/rake/task_manager.rb, line 193
193:     def current_scope
194:       @scope.dup
195:     end
define_task(task_class, *args, &block)
    # File lib/rake/task_manager.rb, line 23
23:     def define_task(task_class, *args, &block)
24:       task_name, arg_names, deps = resolve_args(args)
25:       task_name = task_class.scope_name(@scope, task_name)
26:       deps = [deps] unless deps.respond_to?(:to_ary)
27:       deps = deps.collect {|d| d.to_s }
28:       task = intern(task_class, task_name)
29:       task.set_arg_names(arg_names) unless arg_names.empty?
30:       if Rake::TaskManager.record_task_metadata
31:         add_location(task)
32:         task.add_description(get_description(task))
33:       end
34:       task.enhance(deps, &block)
35:     end
enhance_with_matching_rule(task_name, level=0)

If a rule can be found that matches the task name, enhance the task with the prerequisites and actions from the rule. Set the source attribute of the task appropriately for the rule. Return the enhanced task or nil of no rule was found.

     # File lib/rake/task_manager.rb, line 123
123:     def enhance_with_matching_rule(task_name, level=0)
124:       fail Rake::RuleRecursionOverflowError,
125:         "Rule Recursion Too Deep" if level >= 16
126:       @rules.each do |pattern, extensions, block|
127:         if md = pattern.match(task_name)
128:           task = attempt_rule(task_name, extensions, block, level)
129:           return task if task
130:         end
131:       end
132:       nil
133:     rescue Rake::RuleRecursionOverflowError => ex
134:       ex.add_target(task_name)
135:       fail ex
136:     end
in_namespace(name) {|ns| ...}

Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.

     # File lib/rake/task_manager.rb, line 199
199:     def in_namespace(name)
200:       name ||= generate_name
201:       @scope.push(name)
202:       ns = NameSpace.new(self, @scope)
203:       yield(ns)
204:       ns
205:     ensure
206:       @scope.pop
207:     end
intern(task_class, task_name)

Lookup a task. Return an existing task if found, otherwise create a task of the current type.

    # File lib/rake/task_manager.rb, line 39
39:     def intern(task_class, task_name)
40:       @tasks[task_name.to_s] ||= task_class.new(task_name, self)
41:     end
lookup(task_name, initial_scope=nil)

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.

     # File lib/rake/task_manager.rb, line 163
163:     def lookup(task_name, initial_scope=nil)
164:       initial_scope ||= @scope
165:       task_name = task_name.to_s
166:       if task_name =~ /^rake:/
167:         scopes = []
168:         task_name = task_name.sub(/^rake:/, '')
169:       elsif task_name =~ /^(\^+)/
170:         scopes = initial_scope[0, initial_scope.size - $1.size]
171:         task_name = task_name.sub(/^(\^+)/, '')
172:       else
173:         scopes = initial_scope
174:       end
175:       lookup_in_scope(task_name, scopes)
176:     end
resolve_args(args)

Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].

    # File lib/rake/task_manager.rb, line 59
59:     def resolve_args(args)
60:       if args.last.is_a?(Hash)
61:         deps = args.pop
62:         resolve_args_with_dependencies(args, deps)
63:       else
64:         resolve_args_without_dependencies(args)
65:       end
66:     end
synthesize_file_task(task_name)
    # File lib/rake/task_manager.rb, line 52
52:     def synthesize_file_task(task_name)
53:       return nil unless File.exist?(task_name)
54:       define_task(Rake::FileTask, task_name)
55:     end
tasks()

List of all defined tasks in this application.

     # File lib/rake/task_manager.rb, line 139
139:     def tasks
140:       @tasks.values.sort_by { |t| t.name }
141:     end
tasks_in_scope(scope)

List of all the tasks defined in the given scope (and its sub-scopes).

     # File lib/rake/task_manager.rb, line 145
145:     def tasks_in_scope(scope)
146:       prefix = scope.join(":")
147:       tasks.select { |t|
148:         /^#{prefix}:/ =~ t.name
149:       }
150:     end