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
-
.record_task_metadata ⇒ Object
:nodoc:.
Instance Attribute Summary collapse
-
#last_description ⇒ Object
Track the last comment made in the Rakefile.
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
:nodoc:.
-
#current_scope ⇒ Object
Return the list of scope names currently active in the task manager.
-
#define_task(task_class, *args, &block) ⇒ Object
:nodoc:.
-
#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.
- #generate_did_you_mean_suggestions(task_name) ⇒ Object
- #generate_message_for_undefined_task(task_name) ⇒ Object
-
#in_namespace(name) ⇒ Object
Evaluate the block in a nested namespace named
name
. -
#initialize ⇒ Object
:nodoc:.
-
#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.
-
#synthesize_file_task(task_name) ⇒ Object
:nodoc:.
-
#tasks ⇒ Object
List of all defined tasks in this application.
-
#tasks_in_scope(scope) ⇒ Object
List of all the tasks defined in the given scope (and its sub-scopes).
Class Attribute Details
.record_task_metadata ⇒ Object
:nodoc:
326 327 328 |
# File 'lib/rake/task_manager.rb', line 326 def @record_task_metadata end |
Instance Attribute Details
#last_description ⇒ Object
Track the last comment made in the Rakefile.
7 8 9 |
# File 'lib/rake/task_manager.rb', line 7 def last_description @last_description end |
Instance Method Details
#[](task_name, scopes = nil) ⇒ Object
Find a matching task for task_name
.
54 55 56 57 58 59 60 |
# File 'lib/rake/task_manager.rb', line 54 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 (task_name) end |
#clear ⇒ Object
Clear all tasks in this application.
182 183 184 185 |
# File 'lib/rake/task_manager.rb', line 182 def clear @tasks.clear @rules.clear end |
#create_rule(*args, &block) ⇒ Object
:nodoc:
17 18 19 20 21 |
# File 'lib/rake/task_manager.rb', line 17 def create_rule(*args, &block) # :nodoc: pattern, args, deps, order_only = resolve_args(args) pattern = Regexp.new(Regexp.quote(pattern) + "$") if String === pattern @rules << [pattern, args, deps, order_only, block] end |
#current_scope ⇒ Object
Return the list of scope names currently active in the task manager.
222 223 224 |
# File 'lib/rake/task_manager.rb', line 222 def current_scope @scope end |
#define_task(task_class, *args, &block) ⇒ Object
:nodoc:
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rake/task_manager.rb', line 23 def define_task(task_class, *args, &block) # :nodoc: task_name, arg_names, deps, order_only = resolve_args(args) original_scope = @scope if String === task_name and not task_class.ancestors.include? Rake::FileTask task_name, *definition_scope = *(task_name.split(":").reverse) @scope = Scope.make(*(definition_scope + @scope.to_a)) end task_name = task_class.scope_name(@scope, task_name) 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(Task.format_deps(deps), &block) task | order_only unless order_only.nil? task ensure @scope = original_scope 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rake/task_manager.rb', line 151 def enhance_with_matching_rule(task_name, level=0) fail Rake::RuleRecursionOverflowError, "Rule Recursion Too Deep" if level >= 16 @rules.each do |pattern, args, extensions, order_only, block| if pattern && pattern.match(task_name) task = attempt_rule(task_name, pattern, args, extensions, block, level) task | order_only unless order_only.nil? return task if task end end nil rescue Rake::RuleRecursionOverflowError => ex ex.add_target(task_name) fail ex end |
#generate_did_you_mean_suggestions(task_name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rake/task_manager.rb', line 68 def generate_did_you_mean_suggestions(task_name) return "" unless defined?(::DidYouMean::SpellChecker) suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s) if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later ::DidYouMean.formatter.(suggestions) elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0 ::DidYouMean::Formatter.new(suggestions).to_s else "" end end |
#generate_message_for_undefined_task(task_name) ⇒ Object
62 63 64 65 66 |
# File 'lib/rake/task_manager.rb', line 62 def (task_name) = "Don't know how to build task '#{task_name}' "\ "(See the list of available tasks with `#{Rake.application.name} --tasks`)" + generate_did_you_mean_suggestions(task_name) end |
#in_namespace(name) ⇒ Object
Evaluate the block in a nested namespace named name
. Create an anonymous namespace if name
is nil.
228 229 230 231 232 233 234 235 236 |
# File 'lib/rake/task_manager.rb', line 228 def in_namespace(name) name ||= generate_name @scope = Scope.new(name, @scope) ns = NameSpace.new(self, @scope) yield(ns) ns ensure @scope = @scope.tail end |
#initialize ⇒ Object
:nodoc:
9 10 11 12 13 14 15 |
# File 'lib/rake/task_manager.rb', line 9 def initialize # :nodoc: super @tasks = Hash.new @rules = Array.new @scope = Scope.make @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.
49 50 51 |
# File 'lib/rake/task_manager.rb', line 49 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.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rake/task_manager.rb', line 192 def lookup(task_name, initial_scope=nil) initial_scope ||= @scope task_name = task_name.to_s if task_name =~ /^rake:/ scopes = Scope.make task_name = task_name.sub(/^rake:/, "") elsif task_name =~ /^(\^+)/ scopes = initial_scope.trim($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 tuple of [task_name, arg_name_list, prerequisites, order_only_prerequisites].
88 89 90 91 92 93 94 95 |
# File 'lib/rake/task_manager.rb', line 88 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
:nodoc:
81 82 83 84 |
# File 'lib/rake/task_manager.rb', line 81 def synthesize_file_task(task_name) # :nodoc: return nil unless File.exist?(task_name) define_task(Rake::FileTask, task_name) end |
#tasks ⇒ Object
List of all defined tasks in this application.
168 169 170 |
# File 'lib/rake/task_manager.rb', line 168 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).
174 175 176 177 178 179 |
# File 'lib/rake/task_manager.rb', line 174 def tasks_in_scope(scope) prefix = scope.path tasks.select { |t| /^#{prefix}:/ =~ t.name } end |