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 1429
1429: def initialize
1430: super
1431: @tasks = Hash.new
1432: @rules = Array.new
1433: @scope = Array.new
1434: @last_comment = nil
1435: end
Find a matching task for task_name.
[ show source ]
# File lib/rake.rb, line 1463
1463: def [](task_name, scopes=nil)
1464: task_name = task_name.to_s
1465: self.lookup(task_name, scopes) or
1466: enhance_with_matching_rule(task_name) or
1467: synthesize_file_task(task_name) or
1468: fail "Don't know how to build task '#{task_name}'"
1469: end
Clear all tasks in this application.
[ show source ]
# File lib/rake.rb, line 1517
1517: def clear
1518: @tasks.clear
1519: @rules.clear
1520: end
[ show source ]
# File lib/rake.rb, line 1437
1437: def create_rule(args, &block)
1438: pattern, deps = resolve_args(args)
1439: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
1440: @rules << [pattern, deps, block]
1441: end
Return the list of scope names currently active in the task manager.
[ show source ]
# File lib/rake.rb, line 1557
1557: def current_scope
1558: @scope.dup
1559: end
[ show source ]
# File lib/rake.rb, line 1443
1443: def define_task(task_class, args, &block)
1444: task_name, deps = resolve_args(args)
1445: task_name = task_class.scope_name(@scope, task_name)
1446: deps = [deps] unless deps.respond_to?(:to_ary)
1447: deps = deps.collect {|d| d.to_s }
1448: task = intern(task_class, task_name)
1449: task.application = self
1450: task.add_comment(@last_comment)
1451: @last_comment = nil
1452: task.enhance(deps, &block)
1453: task
1454: 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 1496
1496: def enhance_with_matching_rule(task_name, level=0)
1497: fail Rake::RuleRecursionOverflowError,
1498: "Rule Recursion Too Deep" if level >= 16
1499: @rules.each do |pattern, extensions, block|
1500: if md = pattern.match(task_name)
1501: task = attempt_rule(task_name, extensions, block, level)
1502: return task if task
1503: end
1504: end
1505: nil
1506: rescue Rake::RuleRecursionOverflowError => ex
1507: ex.add_target(task_name)
1508: fail ex
1509: 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 1563
1563: def in_namespace(name)
1564: name ||= generate_name
1565: @scope.push(name)
1566: ns = NameSpace.new(self, @scope)
1567: yield(ns)
1568: ns
1569: ensure
1570: @scope.pop
1571: 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 1458
1458: def intern(task_class, task_name)
1459: @tasks[task_name.to_s] ||= task_class.new(task_name, self)
1460: 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 1527
1527: def lookup(task_name, initial_scope=nil)
1528: initial_scope ||= @scope
1529: task_name = task_name.to_s
1530: if task_name =~ /^rake:/
1531: scopes = []
1532: task_name = task_name.sub(/^rake:/, '')
1533: elsif task_name =~ /^(\^+)/
1534: scopes = initial_scope[0, initial_scope.size - $1.size]
1535: task_name = task_name.sub(/^(\^+)/, '')
1536: else
1537: scopes = initial_scope
1538: end
1539: lookup_in_scope(task_name, scopes)
1540: end
Resolve the arguments for a task/rule.
[ show source ]
# File lib/rake.rb, line 1477
1477: def resolve_args(args)
1478: case args
1479: when Hash
1480: fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
1481: fail "No Task Name Given" if args.size < 1
1482: task_name = args.keys[0]
1483: deps = args[task_name]
1484: deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
1485: else
1486: task_name = args
1487: deps = []
1488: end
1489: [task_name, deps]
1490: end
[ show source ]
# File lib/rake.rb, line 1471
1471: def synthesize_file_task(task_name)
1472: return nil unless File.exist?(task_name)
1473: define_task(Rake::FileTask, task_name)
1474: end
List of all defined tasks in this application.
[ show source ]
# File lib/rake.rb, line 1512
1512: def tasks
1513: @tasks.values.sort_by { |t| t.name }
1514: end