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 1456
1456: def initialize
1457: super
1458: @tasks = Hash.new
1459: @rules = Array.new
1460: @scope = Array.new
1461: @last_comment = nil
1462: end
Find a matching task for task_name.
[ show source ]
# File lib/rake.rb, line 1489
1489: def [](task_name, scopes=nil)
1490: task_name = task_name.to_s
1491: self.lookup(task_name, scopes) or
1492: enhance_with_matching_rule(task_name) or
1493: synthesize_file_task(task_name) or
1494: fail "Don't know how to build task '#{task_name}'"
1495: end
Clear all tasks in this application.
[ show source ]
# File lib/rake.rb, line 1543
1543: def clear
1544: @tasks.clear
1545: @rules.clear
1546: end
[ show source ]
# File lib/rake.rb, line 1464
1464: def create_rule(args, &block)
1465: pattern, deps = resolve_args(args)
1466: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
1467: @rules << [pattern, deps, block]
1468: end
Return the list of scope names currently active in the task manager.
[ show source ]
# File lib/rake.rb, line 1583
1583: def current_scope
1584: @scope.dup
1585: end
[ show source ]
# File lib/rake.rb, line 1470
1470: def define_task(task_class, args, &block)
1471: task_name, deps = resolve_args(args)
1472: task_name = task_class.scope_name(@scope, task_name)
1473: deps = [deps] unless deps.respond_to?(:to_ary)
1474: deps = deps.collect {|d| d.to_s }
1475: task = intern(task_class, task_name)
1476: task.add_comment(@last_comment)
1477: @last_comment = nil
1478: task.enhance(deps, &block)
1479: task
1480: 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 1522
1522: def enhance_with_matching_rule(task_name, level=0)
1523: fail Rake::RuleRecursionOverflowError,
1524: "Rule Recursion Too Deep" if level >= 16
1525: @rules.each do |pattern, extensions, block|
1526: if md = pattern.match(task_name)
1527: task = attempt_rule(task_name, extensions, block, level)
1528: return task if task
1529: end
1530: end
1531: nil
1532: rescue Rake::RuleRecursionOverflowError => ex
1533: ex.add_target(task_name)
1534: fail ex
1535: 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 1589
1589: def in_namespace(name)
1590: name ||= generate_name
1591: @scope.push(name)
1592: ns = NameSpace.new(self, @scope)
1593: yield(ns)
1594: ns
1595: ensure
1596: @scope.pop
1597: 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 1484
1484: def intern(task_class, task_name)
1485: @tasks[task_name.to_s] ||= task_class.new(task_name, self)
1486: 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 1553
1553: def lookup(task_name, initial_scope=nil)
1554: initial_scope ||= @scope
1555: task_name = task_name.to_s
1556: if task_name =~ /^rake:/
1557: scopes = []
1558: task_name = task_name.sub(/^rake:/, '')
1559: elsif task_name =~ /^(\^+)/
1560: scopes = initial_scope[0, initial_scope.size - $1.size]
1561: task_name = task_name.sub(/^(\^+)/, '')
1562: else
1563: scopes = initial_scope
1564: end
1565: lookup_in_scope(task_name, scopes)
1566: end
Resolve the arguments for a task/rule.
[ show source ]
# File lib/rake.rb, line 1503
1503: def resolve_args(args)
1504: case args
1505: when Hash
1506: fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
1507: fail "No Task Name Given" if args.size < 1
1508: task_name = args.keys[0]
1509: deps = args[task_name]
1510: deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
1511: else
1512: task_name = args
1513: deps = []
1514: end
1515: [task_name, deps]
1516: end
[ show source ]
# File lib/rake.rb, line 1497
1497: def synthesize_file_task(task_name)
1498: return nil unless File.exist?(task_name)
1499: define_task(Rake::FileTask, task_name)
1500: end
List of all defined tasks in this application.
[ show source ]
# File lib/rake.rb, line 1538
1538: def tasks
1539: @tasks.values.sort_by { |t| t.name }
1540: end