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 1596 1596: def initialize 1597: super 1598: @tasks = Hash.new 1599: @rules = Array.new 1600: @scope = Array.new 1601: @last_description = nil 1602: end
Find a matching task for task_name.
# File lib/rake.rb, line 1630 1630: def [](task_name, scopes=nil) 1631: task_name = task_name.to_s 1632: self.lookup(task_name, scopes) or 1633: enhance_with_matching_rule(task_name) or 1634: synthesize_file_task(task_name) or 1635: fail "Don't know how to build task '#{task_name}'" 1636: end
# File lib/rake.rb, line 1604 1604: def create_rule(*args, &block) 1605: pattern, arg_names, deps = resolve_args(args) 1606: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 1607: @rules << [pattern, deps, block] 1608: end
Return the list of scope names currently active in the task manager.
# File lib/rake.rb, line 1728 1728: def current_scope 1729: @scope.dup 1730: end
# File lib/rake.rb, line 1610 1610: def define_task(task_class, *args, &block) 1611: task_name, arg_names, deps = resolve_args(args) 1612: task_name = task_class.scope_name(@scope, task_name) 1613: deps = [deps] unless deps.respond_to?(:to_ary) 1614: deps = deps.collect {|d| d.to_s } 1615: task = intern(task_class, task_name) 1616: task.set_arg_names(arg_names) unless arg_names.empty? 1617: task.add_description(@last_description) 1618: @last_description = nil 1619: task.enhance(deps, &block) 1620: task 1621: 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 1667 1667: def enhance_with_matching_rule(task_name, level=0) 1668: fail Rake::RuleRecursionOverflowError, 1669: "Rule Recursion Too Deep" if level >= 16 1670: @rules.each do |pattern, extensions, block| 1671: if md = pattern.match(task_name) 1672: task = attempt_rule(task_name, extensions, block, level) 1673: return task if task 1674: end 1675: end 1676: nil 1677: rescue Rake::RuleRecursionOverflowError => ex 1678: ex.add_target(task_name) 1679: fail ex 1680: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
# File lib/rake.rb, line 1734 1734: def in_namespace(name) 1735: name ||= generate_name 1736: @scope.push(name) 1737: ns = NameSpace.new(self, @scope) 1738: yield(ns) 1739: ns 1740: ensure 1741: @scope.pop 1742: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
# File lib/rake.rb, line 1625 1625: def intern(task_class, task_name) 1626: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 1627: 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 1698 1698: def lookup(task_name, initial_scope=nil) 1699: initial_scope ||= @scope 1700: task_name = task_name.to_s 1701: if task_name =~ /^rake:/ 1702: scopes = [] 1703: task_name = task_name.sub(/^rake:/, '') 1704: elsif task_name =~ /^(\^+)/ 1705: scopes = initial_scope[0, initial_scope.size - $1.size] 1706: task_name = task_name.sub(/^(\^+)/, '') 1707: else 1708: scopes = initial_scope 1709: end 1710: lookup_in_scope(task_name, scopes) 1711: end
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
# File lib/rake.rb, line 1645 1645: def resolve_args(args) 1646: task_name = args.shift 1647: arg_names = args #.map { |a| a.to_sym } 1648: needs = [] 1649: if task_name.is_a?(Hash) 1650: hash = task_name 1651: task_name = hash.keys[0] 1652: needs = hash[task_name] 1653: end 1654: if arg_names.last.is_a?(Hash) 1655: hash = arg_names.pop 1656: needs = hash[:needs] 1657: fail "Unrecognized keys in task hash: #{hash.keys.inspect}" if hash.size > 1 1658: end 1659: needs = [needs] unless needs.respond_to?(:to_ary) 1660: [task_name, arg_names, needs] 1661: end