Module: Rake::TaskManager

### Home Classes Methods

### In Files

- lib/rake/task_manager.rb

### Methods

- ::new
- #[]
- #clear
- #create_rule
- #current_scope
- #define_task
- #enhance_with_matching_rule
- #in_namespace
- #intern
- #lookup
- #resolve_args
- #synthesize_file_task
- #tasks
- #tasks_in_scope

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- command_line_usage.rdoc
- glossary.rdoc
- proto_rake.rdoc
- rakefile.rdoc
- rational.rdoc
- rake-0.4.14.rdoc
- rake-0.4.15.rdoc
- rake-0.5.0.rdoc
- rake-0.5.3.rdoc
- rake-0.5.4.rdoc
- rake-0.6.0.rdoc
- rake-0.7.0.rdoc
- rake-0.7.1.rdoc
- rake-0.7.2.rdoc
- rake-0.7.3.rdoc
- rake-0.8.0.rdoc
- rake-0.8.4.rdoc
- rake-0.8.5.rdoc
- rake-0.8.6.rdoc
- rake-0.8.7.rdoc

### Class/Module Index

Quicksearch

- Rake
- Rake::AltSystem
- Rake::Application
- Rake::Backtrace
- Rake::Cloneable
- Rake::CompositePublisher
- Rake::DSL
- Rake::DefaultLoader
- Rake::EarlyTime
- Rake::FileCreationTask
- Rake::FileList
- Rake::FileTask
- Rake::FileUtilsExt
- Rake::FtpFile
- Rake::FtpUploader
- Rake::InvocationChain
- Rake::InvocationChain::EmptyInvocationChain
- Rake::InvocationExceptionMixin
- Rake::MakefileLoader
- Rake::MultiTask
- Rake::NameSpace
- Rake::PackageTask
- Rake::PseudoStatus
- Rake::RubyForgePublisher
- Rake::RuleRecursionOverflowError
- Rake::SshDirPublisher
- Rake::SshFilePublisher
- Rake::SshFreshDirPublisher
- Rake::Task
- Rake::TaskArgumentError
- Rake::TaskArguments
- Rake::TaskLib
- Rake::TaskManager
- Rake::TestTask
- Rake::TraceOutput
- Rake::Win32
- Rake::Win32::Win32HomeError
- CompositePublisher
- FileUtils
- Module
- Object
- SshDirPublisher
- SshFilePublisher
- SshFreshDirPublisher
- String
- Time

No matching classes.

# Rake::TaskManager

The TaskManager module is a mixin for managing tasks.

### Attributes

last_comment[RW]

Track the last comment made in the Rakefile.

last_description[RW]

Track the last comment made in the Rakefile.

### Public Class Methods

new() click to toggle source

    # File lib/rake/task_manager.rb, line 9
    def initialize
      super
      @tasks = Hash.new
      @rules = Array.new
      @scope = Array.new
      @last_description = nil
    end

### Public Instance Methods

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

Find a matching task for `task_name`.

    # 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

clear() click to toggle source

Clear all tasks in this application.

    # File lib/rake/task_manager.rb, line 146
    def clear
      @tasks.clear
      @rules.clear
    end

create_rule(*args, &block) click to toggle source

    # 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_scope() click to toggle source

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

    # File lib/rake/task_manager.rb, line 186
    def current_scope
      @scope.dup
    end

define_task(task_class, *args, &block) click to toggle source

    # 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.record_task_metadata
        add_location(task)
        task.add_description(get_description(task))
      end
      task.enhance(deps, &block)
    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 lib/rake/task_manager.rb, line 116
    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) click to toggle source

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

    # File lib/rake/task_manager.rb, line 192
    def in_namespace(name)
      name ||= generate_name
      @scope.push(name)
      ns = NameSpace.new(self, @scope)
      yield(ns)
      ns
    ensure
      @scope.pop
    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 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) 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 lib/rake/task_manager.rb, line 156
    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) click to toggle source

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

    # 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

tasks() click to toggle source

List of all defined tasks in this application.

    # File lib/rake/task_manager.rb, line 132
    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 lib/rake/task_manager.rb, line 138
    def tasks_in_scope(scope)
      prefix = scope.join(":")
      tasks.select { |t|
        /^#{prefix}:/ =~ t.name
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.