In Files

  • rake-13.0.1/lib/rake/task_manager.rb

Rake::TaskManager

The TaskManager module is a mixin for managing tasks.

Attributes

last_description[RW]

Track the last comment made in the Rakefile.

Public Instance Methods

[](task_name, scopes=nil) click to toggle source

Find a matching task for task_name.

 
               # File rake-13.0.1/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 generate_message_for_undefined_task(task_name)
end
            
clear() click to toggle source

Clear all tasks in this application.

 
               # File rake-13.0.1/lib/rake/task_manager.rb, line 182
def clear
  @tasks.clear
  @rules.clear
end
            
current_scope() click to toggle source

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

 
               # File rake-13.0.1/lib/rake/task_manager.rb, line 222
def current_scope
  @scope
end
            
enhance_with_matching_rule(task_name, level=0) click to toggle source

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 rake-13.0.1/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) click to toggle source
 
               # File rake-13.0.1/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.message_for(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) click to toggle source
 
               # File rake-13.0.1/lib/rake/task_manager.rb, line 62
def generate_message_for_undefined_task(task_name)
  message = "Don't know how to build task '#{task_name}' "\
            "(See the list of available tasks with `#{Rake.application.name} --tasks`)"
  message + generate_did_you_mean_suggestions(task_name)
end
            
in_namespace(name) click to toggle source

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

 
               # File rake-13.0.1/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
            
intern(task_class, task_name) click to toggle source

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

 
               # File rake-13.0.1/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) click to toggle source

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 rake-13.0.1/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) click to toggle source

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

 
               # File rake-13.0.1/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
            
tasks() click to toggle source

List of all defined tasks in this application.

 
               # File rake-13.0.1/lib/rake/task_manager.rb, line 168
def tasks
  @tasks.values.sort_by { |t| t.name }
end
            
tasks_in_scope(scope) click to toggle source

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

 
               # File rake-13.0.1/lib/rake/task_manager.rb, line 174
def tasks_in_scope(scope)
  prefix = scope.path
  tasks.select { |t|
    /^#{prefix}:/ =~ t.name
  }
end