Module | Rake::TaskManager |
In: |
lib/rake.rb
|
The TaskManager module is a mixin for managing tasks.
last_description | -> | last_comment |
last_description | [RW] | Track the last comment made in the Rakefile. |
# File lib/rake.rb, line 1668 1668: def initialize 1669: super 1670: @tasks = Hash.new 1671: @rules = Array.new 1672: @scope = Array.new 1673: @last_description = nil 1674: end
Find a matching task for task_name.
# File lib/rake.rb, line 1702 1702: def [](task_name, scopes=nil) 1703: task_name = task_name.to_s 1704: self.lookup(task_name, scopes) or 1705: enhance_with_matching_rule(task_name) or 1706: synthesize_file_task(task_name) or 1707: fail "Don't know how to build task '#{task_name}'" 1708: end
# File lib/rake.rb, line 1676 1676: def create_rule(*args, &block) 1677: pattern, arg_names, deps = resolve_args(args) 1678: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 1679: @rules << [pattern, deps, block] 1680: end
Return the list of scope names currently active in the task manager.
# File lib/rake.rb, line 1842 1842: def current_scope 1843: @scope.dup 1844: end
# File lib/rake.rb, line 1682 1682: def define_task(task_class, *args, &block) 1683: task_name, arg_names, deps = resolve_args(args) 1684: task_name = task_class.scope_name(@scope, task_name) 1685: deps = [deps] unless deps.respond_to?(:to_ary) 1686: deps = deps.collect {|d| d.to_s } 1687: task = intern(task_class, task_name) 1688: task.set_arg_names(arg_names) unless arg_names.empty? 1689: task.add_description(@last_description) 1690: @last_description = nil 1691: task.enhance(deps, &block) 1692: task 1693: 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.
# File lib/rake.rb, line 1781 1781: def enhance_with_matching_rule(task_name, level=0) 1782: fail Rake::RuleRecursionOverflowError, 1783: "Rule Recursion Too Deep" if level >= 16 1784: @rules.each do |pattern, extensions, block| 1785: if md = pattern.match(task_name) 1786: task = attempt_rule(task_name, extensions, block, level) 1787: return task if task 1788: end 1789: end 1790: nil 1791: rescue Rake::RuleRecursionOverflowError => ex 1792: ex.add_target(task_name) 1793: fail ex 1794: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
# File lib/rake.rb, line 1848 1848: def in_namespace(name) 1849: name ||= generate_name 1850: @scope.push(name) 1851: ns = NameSpace.new(self, @scope) 1852: yield(ns) 1853: ns 1854: ensure 1855: @scope.pop 1856: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
# File lib/rake.rb, line 1697 1697: def intern(task_class, task_name) 1698: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 1699: 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.
# File lib/rake.rb, line 1812 1812: def lookup(task_name, initial_scope=nil) 1813: initial_scope ||= @scope 1814: task_name = task_name.to_s 1815: if task_name =~ /^rake:/ 1816: scopes = [] 1817: task_name = task_name.sub(/^rake:/, '') 1818: elsif task_name =~ /^(\^+)/ 1819: scopes = initial_scope[0, initial_scope.size - $1.size] 1820: task_name = task_name.sub(/^(\^+)/, '') 1821: else 1822: scopes = initial_scope 1823: end 1824: lookup_in_scope(task_name, scopes) 1825: end
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
# File lib/rake.rb, line 1717 1717: def resolve_args(args) 1718: if args.last.is_a?(Hash) 1719: deps = args.pop 1720: resolve_args_with_dependencies(args, deps) 1721: else 1722: resolve_args_without_dependencies(args) 1723: end 1724: end