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