The TaskManager module is a mixin for managing tasks.
- []
- clear
- create_rule
- current_scope
- define_task
- enhance_with_matching_rule
- in_namespace
- intern
- lookup
- new
- resolve_args
- synthesize_file_task
- tasks
[RW] | last_comment | Track the last comment made in the Rakefile. |
[ show source ]
# File lib/rake.rb, line 1411 1411: def initialize 1412: super 1413: @tasks = Hash.new 1414: @rules = Array.new 1415: @scope = Array.new 1416: @last_comment = nil 1417: end
Find a matching task for task_name.
[ show source ]
# File lib/rake.rb, line 1445 1445: def [](task_name, scopes=nil) 1446: task_name = task_name.to_s 1447: self.lookup(task_name, scopes) or 1448: enhance_with_matching_rule(task_name) or 1449: synthesize_file_task(task_name) or 1450: fail "Don't know how to build task '#{task_name}'" 1451: end
Clear all tasks in this application.
[ show source ]
# File lib/rake.rb, line 1499 1499: def clear 1500: @tasks.clear 1501: @rules.clear 1502: end
[ show source ]
# File lib/rake.rb, line 1419 1419: def create_rule(args, &block) 1420: pattern, deps = resolve_args(args) 1421: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern 1422: @rules << [pattern, deps, block] 1423: end
Return the list of scope names currently active in the task manager.
[ show source ]
# File lib/rake.rb, line 1539 1539: def current_scope 1540: @scope.dup 1541: end
[ show source ]
# File lib/rake.rb, line 1425 1425: def define_task(task_class, args, &block) 1426: task_name, deps = resolve_args(args) 1427: task_name = task_class.scope_name(@scope, task_name) 1428: deps = [deps] unless deps.respond_to?(:to_ary) 1429: deps = deps.collect {|d| d.to_s } 1430: task = intern(task_class, task_name) 1431: task.application = self 1432: task.add_comment(@last_comment) 1433: @last_comment = nil 1434: task.enhance(deps, &block) 1435: task 1436: 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.
[ show source ]
# File lib/rake.rb, line 1478 1478: def enhance_with_matching_rule(task_name, level=0) 1479: fail Rake::RuleRecursionOverflowError, 1480: "Rule Recursion Too Deep" if level >= 16 1481: @rules.each do |pattern, extensions, block| 1482: if md = pattern.match(task_name) 1483: task = attempt_rule(task_name, extensions, block, level) 1484: return task if task 1485: end 1486: end 1487: nil 1488: rescue Rake::RuleRecursionOverflowError => ex 1489: ex.add_target(task_name) 1490: fail ex 1491: end
Evaluate the block in a nested namespace named name. Create an anonymous namespace if name is nil.
[ show source ]
# File lib/rake.rb, line 1545 1545: def in_namespace(name) 1546: name ||= generate_name 1547: @scope.push(name) 1548: ns = NameSpace.new(self, @scope) 1549: yield(ns) 1550: ns 1551: ensure 1552: @scope.pop 1553: end
Lookup a task. Return an existing task if found, otherwise create a task of the current type.
[ show source ]
# File lib/rake.rb, line 1440 1440: def intern(task_class, task_name) 1441: @tasks[task_name.to_s] ||= task_class.new(task_name, self) 1442: 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.
[ show source ]
# File lib/rake.rb, line 1509 1509: def lookup(task_name, initial_scope=nil) 1510: initial_scope ||= @scope 1511: task_name = task_name.to_s 1512: if task_name =~ /^rake:/ 1513: scopes = [] 1514: task_name = task_name.sub(/^rake:/, '') 1515: elsif task_name =~ /^(\^^+)/ 1516: scopes = initial_scope[0, initial_scope.size - $1.size] 1517: task_name = task_name.sub(/^(\^^+)/, '') 1518: else 1519: scopes = initial_scope 1520: end 1521: lookup_in_scope(task_name, scopes) 1522: end
Resolve the arguments for a task/rule.
[ show source ]
# File lib/rake.rb, line 1459 1459: def resolve_args(args) 1460: case args 1461: when Hash 1462: fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1 1463: fail "No Task Name Given" if args.size < 1 1464: task_name = args.keys[0] 1465: deps = args[task_name] 1466: deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps) 1467: else 1468: task_name = args 1469: deps = [] 1470: end 1471: [task_name, deps] 1472: end
[ show source ]
# File lib/rake.rb, line 1453 1453: def synthesize_file_task(task_name) 1454: return nil unless File.exist?(task_name) 1455: define_task(Rake::FileTask, task_name) 1456: end
List of all defined tasks in this application.
[ show source ]
# File lib/rake.rb, line 1494 1494: def tasks 1495: @tasks.values.sort_by { |t| t.name } 1496: end