Module | Rake::TaskManager |
In: |
lib/rake.rb
|
The TaskManager module is a mixin for managing tasks.
last_comment | [RW] | Track the last comment made in the Rakefile. |
# File lib/rake.rb, line 1436 1436: def initialize 1437: super 1438: @tasks = Hash.new 1439: @rules = Array.new 1440: @scope = Array.new 1441: @last_comment = nil 1442: end
Find a matching task for task_name.
# File lib/rake.rb, line 1469 1469: def [](task_name, scopes=nil) 1470: task_name = task_name.to_s 1471: self.lookup(task_name, scopes) or 1472: enhance_with_matching_rule(task_name) or 1473: synthesize_file_task(task_name) or 1474: fail "Don't know how to build task '#{task_name}'" 1475: end
# File lib/rake.rb, line 1444 1444: def create_rule(args, &block) 1445: pattern, deps = resolve_args(args) 1446: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 1447: @rules << [pattern, deps, block] 1448: end
Return the list of scope names currently active in the task manager.
# File lib/rake.rb, line 1563 1563: def current_scope 1564: @scope.dup 1565: end
# File lib/rake.rb, line 1450 1450: def define_task(task_class, args, &block) 1451: task_name, deps = resolve_args(args) 1452: task_name = task_class.scope_name(@scope, task_name) 1453: deps = [deps] unless deps.respond_to?(:to_ary) 1454: deps = deps.collect {|d| d.to_s } 1455: task = intern(task_class, task_name) 1456: task.add_comment(@last_comment) 1457: @last_comment = nil 1458: task.enhance(deps, &block) 1459: task 1460: 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 1502 1502: def enhance_with_matching_rule(task_name, level=0) 1503: fail Rake::RuleRecursionOverflowError, 1504: "Rule Recursion Too Deep" if level >= 16 1505: @rules.each do |pattern, extensions, block| 1506: if md = pattern.match(task_name) 1507: task = attempt_rule(task_name, extensions, block, level) 1508: return task if task 1509: end 1510: end 1511: nil 1512: rescue Rake::RuleRecursionOverflowError => ex 1513: ex.add_target(task_name) 1514: fail ex 1515: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
# File lib/rake.rb, line 1569 1569: def in_namespace(name) 1570: name ||= generate_name 1571: @scope.push(name) 1572: ns = NameSpace.new(self, @scope) 1573: yield(ns) 1574: ns 1575: ensure 1576: @scope.pop 1577: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
# File lib/rake.rb, line 1464 1464: def intern(task_class, task_name) 1465: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 1466: 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 1533 1533: def lookup(task_name, initial_scope=nil) 1534: initial_scope ||= @scope 1535: task_name = task_name.to_s 1536: if task_name =~ /^rake:/ 1537: scopes = [] 1538: task_name = task_name.sub(/^rake:/, '') 1539: elsif task_name =~ /^(\^+)/ 1540: scopes = initial_scope[0, initial_scope.size - $1.size] 1541: task_name = task_name.sub(/^(\^+)/, '') 1542: else 1543: scopes = initial_scope 1544: end 1545: lookup_in_scope(task_name, scopes) 1546: end
Resolve the arguments for a task/rule.
# File lib/rake.rb, line 1483 1483: def resolve_args(args) 1484: case args 1485: when Hash 1486: fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1 1487: fail "No Task Name Given" if args.size < 1 1488: task_name = args.keys[0] 1489: deps = args[task_name] 1490: deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps) 1491: else 1492: task_name = args 1493: deps = [] 1494: end 1495: [task_name, deps] 1496: end