Module Rake::TaskManager
In: lib/rake.rb

The TaskManager module is a mixin for managing tasks.

Methods

External Aliases

last_description -> last_comment

Attributes

last_description  [RW]  Track the last comment made in the Rakefile.

Public Class methods

[Source]

      # File lib/rake.rb, line 1666
1666:     def initialize
1667:       super
1668:       @tasks = Hash.new
1669:       @rules = Array.new
1670:       @scope = Array.new
1671:       @last_description = nil
1672:     end

Public Instance methods

Find a matching task for task_name.

[Source]

      # File lib/rake.rb, line 1700
1700:     def [](task_name, scopes=nil)
1701:       task_name = task_name.to_s
1702:       self.lookup(task_name, scopes) or
1703:         enhance_with_matching_rule(task_name) or
1704:         synthesize_file_task(task_name) or
1705:         fail "Don't know how to build task '#{task_name}'"
1706:     end

Clear all tasks in this application.

[Source]

      # File lib/rake.rb, line 1809
1809:     def clear
1810:       @tasks.clear
1811:       @rules.clear
1812:     end

[Source]

      # File lib/rake.rb, line 1674
1674:     def create_rule(*args, &block)
1675:       pattern, arg_names, deps = resolve_args(args)
1676:       pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
1677:       @rules << [pattern, deps, block]
1678:     end

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

[Source]

      # File lib/rake.rb, line 1849
1849:     def current_scope
1850:       @scope.dup
1851:     end

[Source]

      # File lib/rake.rb, line 1680
1680:     def define_task(task_class, *args, &block)
1681:       task_name, arg_names, deps = resolve_args(args)
1682:       task_name = task_class.scope_name(@scope, task_name)
1683:       deps = [deps] unless deps.respond_to?(:to_ary)
1684:       deps = deps.collect {|d| d.to_s }
1685:       task = intern(task_class, task_name)
1686:       task.set_arg_names(arg_names) unless arg_names.empty?
1687:       task.add_description(@last_description)
1688:       @last_description = nil
1689:       task.enhance(deps, &block)
1690:       task
1691:     end

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.

[Source]

      # File lib/rake.rb, line 1779
1779:     def enhance_with_matching_rule(task_name, level=0)
1780:       fail Rake::RuleRecursionOverflowError,
1781:         "Rule Recursion Too Deep" if level >= 16
1782:       @rules.each do |pattern, extensions, block|
1783:         if md = pattern.match(task_name)
1784:           task = attempt_rule(task_name, extensions, block, level)
1785:           return task if task
1786:         end
1787:       end
1788:       nil
1789:     rescue Rake::RuleRecursionOverflowError => ex
1790:       ex.add_target(task_name)
1791:       fail ex
1792:     end

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

[Source]

      # File lib/rake.rb, line 1855
1855:     def in_namespace(name)
1856:       name ||= generate_name
1857:       @scope.push(name)
1858:       ns = NameSpace.new(self, @scope)
1859:       yield(ns)
1860:       ns
1861:     ensure
1862:       @scope.pop
1863:     end

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

[Source]

      # File lib/rake.rb, line 1695
1695:     def intern(task_class, task_name)
1696:       @tasks[task_name.to_s] ||= task_class.new(task_name, self)
1697:     end

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.

[Source]

      # File lib/rake.rb, line 1819
1819:     def lookup(task_name, initial_scope=nil)
1820:       initial_scope ||= @scope
1821:       task_name = task_name.to_s
1822:       if task_name =~ /^rake:/
1823:         scopes = []
1824:         task_name = task_name.sub(/^rake:/, '')
1825:       elsif task_name =~ /^(\^+)/
1826:         scopes = initial_scope[0, initial_scope.size - $1.size]
1827:         task_name = task_name.sub(/^(\^+)/, '')
1828:       else
1829:         scopes = initial_scope
1830:       end
1831:       lookup_in_scope(task_name, scopes)
1832:     end

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

[Source]

      # File lib/rake.rb, line 1715
1715:     def resolve_args(args)
1716:       if args.last.is_a?(Hash)
1717:         deps = args.pop
1718:         resolve_args_with_dependencies(args, deps)
1719:       else
1720:         resolve_args_without_dependencies(args)
1721:       end
1722:     end

[Source]

      # File lib/rake.rb, line 1708
1708:     def synthesize_file_task(task_name)
1709:       return nil unless File.exist?(task_name)
1710:       define_task(Rake::FileTask, task_name)
1711:     end

List of all defined tasks in this application.

[Source]

      # File lib/rake.rb, line 1795
1795:     def tasks
1796:       @tasks.values.sort_by { |t| t.name }
1797:     end

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

[Source]

      # File lib/rake.rb, line 1801
1801:     def tasks_in_scope(scope)
1802:       prefix = scope.join(":")
1803:       tasks.select { |t|
1804:         /^#{prefix}:/ =~ t.name
1805:       }
1806:     end

[Validate]