Module: Rake::TaskManager

Included in:
Application
Defined in:
lib/rake/task_manager.rb

Overview

The TaskManager module is a mixin for managing tasks.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.record_task_metadataObject

Returns the value of attribute record_task_metadata



302
303
304
# File 'lib/rake/task_manager.rb', line 302

def 
  @record_task_metadata
end

Instance Attribute Details

#last_descriptionObject Also known as: last_comment

Track the last comment made in the Rakefile.



6
7
8
# File 'lib/rake/task_manager.rb', line 6

def last_description
  @last_description
end

Instance Method Details

#[](task_name, scopes = nil) ⇒ Object

Find a matching task for task_name.



44
45
46
47
48
49
50
# File 'lib/rake/task_manager.rb', line 44

def [](task_name, scopes=nil)
  task_name = task_name.to_s
  self.lookup(task_name, scopes) or
    enhance_with_matching_rule(task_name) or
    synthesize_file_task(task_name) or
    fail "Don't know how to build task '#{task_name}'"
end

#clearObject

Clear all tasks in this application.



157
158
159
160
# File 'lib/rake/task_manager.rb', line 157

def clear
  @tasks.clear
  @rules.clear
end

#create_rule(*args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/rake/task_manager.rb', line 17

def create_rule(*args, &block)
  pattern, _, deps = resolve_args(args)
  pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
  @rules << [pattern, deps, block]
end

#current_scopeObject

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



197
198
199
# File 'lib/rake/task_manager.rb', line 197

def current_scope
  @scope.dup
end

#define_task(task_class, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rake/task_manager.rb', line 23

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?
  if Rake::TaskManager.
    add_location(task)
    task.add_description(get_description(task))
  end
  task.enhance(deps, &block)
end

#enhance_with_matching_rule(task_name, level = 0) ⇒ Object

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.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rake/task_manager.rb', line 127

def enhance_with_matching_rule(task_name, level=0)
  fail Rake::RuleRecursionOverflowError,
    "Rule Recursion Too Deep" if level >= 16
  @rules.each do |pattern, extensions, block|
    if pattern.match(task_name)
      task = attempt_rule(task_name, extensions, block, level)
      return task if task
    end
  end
  nil
rescue Rake::RuleRecursionOverflowError => ex
  ex.add_target(task_name)
  fail ex
end

#in_namespace(name) ⇒ Object

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



203
204
205
206
207
208
209
210
211
# File 'lib/rake/task_manager.rb', line 203

def in_namespace(name)
  name ||= generate_name
  @scope.push(name)
  ns = NameSpace.new(self, @scope)
  yield(ns)
  ns
ensure
  @scope.pop
end

#initializeTaskManager

Returns a new instance of TaskManager.

Returns:



9
10
11
12
13
14
15
# File 'lib/rake/task_manager.rb', line 9

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.



39
40
41
# File 'lib/rake/task_manager.rb', line 39

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.



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rake/task_manager.rb', line 167

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].



59
60
61
62
63
64
65
66
# File 'lib/rake/task_manager.rb', line 59

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

#synthesize_file_task(task_name) ⇒ Object



52
53
54
55
# File 'lib/rake/task_manager.rb', line 52

def synthesize_file_task(task_name)
  return nil unless File.exist?(task_name)
  define_task(Rake::FileTask, task_name)
end

#tasksObject

List of all defined tasks in this application.



143
144
145
# File 'lib/rake/task_manager.rb', line 143

def tasks
  @tasks.values.sort_by { |t| t.name }
end

#tasks_in_scope(scope) ⇒ Object

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



149
150
151
152
153
154
# File 'lib/rake/task_manager.rb', line 149

def tasks_in_scope(scope)
  prefix = scope.join(":")
  tasks.select { |t|
    /^#{prefix}:/ =~ t.name
  }
end