Module
Rake::TaskManager
In: lib/rake.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,
Attributes

 [RW]  last_comment Track the last comment made in the Rakefile.
Public Class methods
new()
      # File lib/rake.rb, line 1435
1435:     def initialize
1436:       super
1437:       @tasks = Hash.new
1438:       @rules = Array.new
1439:       @scope = Array.new
1440:       @last_comment = nil
1441:     end
Public Instance methods
[](task_name, scopes=nil)

Find a matching task for task_name.

      # File lib/rake.rb, line 1468
1468:     def [](task_name, scopes=nil)
1469:       task_name = task_name.to_s
1470:       self.lookup(task_name, scopes) or
1471:         enhance_with_matching_rule(task_name) or
1472:         synthesize_file_task(task_name) or
1473:         fail "Don't know how to build task '#{task_name}'"
1474:     end
clear()

Clear all tasks in this application.

      # File lib/rake.rb, line 1522
1522:     def clear
1523:       @tasks.clear
1524:       @rules.clear
1525:     end
create_rule(args, &block)
      # File lib/rake.rb, line 1443
1443:     def create_rule(args, &block)
1444:       pattern, deps = resolve_args(args)
1445:       pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
1446:       @rules << [pattern, deps, block]
1447:     end
current_scope()

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

      # File lib/rake.rb, line 1562
1562:     def current_scope
1563:       @scope.dup
1564:     end
define_task(task_class, args, &block)
      # File lib/rake.rb, line 1449
1449:     def define_task(task_class, args, &block)
1450:       task_name, deps = resolve_args(args)
1451:       task_name = task_class.scope_name(@scope, task_name)
1452:       deps = [deps] unless deps.respond_to?(:to_ary)
1453:       deps = deps.collect {|d| d.to_s }
1454:       task = intern(task_class, task_name)
1455:       task.add_comment(@last_comment)
1456:       @last_comment = nil
1457:       task.enhance(deps, &block)
1458:       task
1459:     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.rb, line 1501
1501:     def enhance_with_matching_rule(task_name, level=0)
1502:       fail Rake::RuleRecursionOverflowError,
1503:         "Rule Recursion Too Deep" if level >= 16
1504:       @rules.each do |pattern, extensions, block|
1505:         if md = pattern.match(task_name)
1506:           task = attempt_rule(task_name, extensions, block, level)
1507:           return task if task
1508:         end
1509:       end
1510:       nil
1511:     rescue Rake::RuleRecursionOverflowError => ex
1512:       ex.add_target(task_name)
1513:       fail ex
1514:     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.rb, line 1568
1568:     def in_namespace(name)
1569:       name ||= generate_name
1570:       @scope.push(name)
1571:       ns = NameSpace.new(self, @scope)
1572:       yield(ns)
1573:       ns
1574:     ensure
1575:       @scope.pop
1576:     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.rb, line 1463
1463:     def intern(task_class, task_name)
1464:       @tasks[task_name.to_s] ||= task_class.new(task_name, self)
1465:     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.rb, line 1532
1532:     def lookup(task_name, initial_scope=nil)
1533:       initial_scope ||= @scope
1534:       task_name = task_name.to_s
1535:       if task_name =~ /^rake:/
1536:         scopes = []
1537:         task_name = task_name.sub(/^rake:/, '')
1538:       elsif task_name =~ /^(\^+)/
1539:         scopes = initial_scope[0, initial_scope.size - $1.size]
1540:         task_name = task_name.sub(/^(\^+)/, '')
1541:       else
1542:         scopes = initial_scope
1543:       end
1544:       lookup_in_scope(task_name, scopes)
1545:     end
resolve_args(args)

Resolve the arguments for a task/rule.

      # File lib/rake.rb, line 1482
1482:     def resolve_args(args)
1483:       case args
1484:       when Hash
1485:         fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
1486:         fail "No Task Name Given" if args.size < 1
1487:         task_name = args.keys[0]
1488:         deps = args[task_name]
1489:         deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
1490:       else
1491:         task_name = args
1492:         deps = []
1493:       end
1494:       [task_name, deps]
1495:     end
synthesize_file_task(task_name)
      # File lib/rake.rb, line 1476
1476:     def synthesize_file_task(task_name)
1477:       return nil unless File.exist?(task_name)
1478:       define_task(Rake::FileTask, task_name)
1479:     end
tasks()

List of all defined tasks in this application.

      # File lib/rake.rb, line 1517
1517:     def tasks
1518:       @tasks.values.sort_by { |t| t.name }
1519:     end