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_description ⇒ Object
(also: #last_comment)
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_description ⇒ Object Also known as: last_comment
Track the last comment made in the Rakefile.
1664 1665 1666 |
# File 'lib/rake.rb', line 1664 def last_description @last_description end |
Instance Method Details
#[](task_name, scopes = nil) ⇒ Object
Find a matching task for task_name
.
1701 1702 1703 1704 1705 1706 1707 |
# File 'lib/rake.rb', line 1701 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.
1801 1802 1803 1804 |
# File 'lib/rake.rb', line 1801 def clear @tasks.clear @rules.clear end |
#create_rule(*args, &block) ⇒ Object
1675 1676 1677 1678 1679 |
# File 'lib/rake.rb', line 1675 def create_rule(*args, &block) pattern, arg_names, 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.
1841 1842 1843 |
# File 'lib/rake.rb', line 1841 def current_scope @scope.dup end |
#define_task(task_class, *args, &block) ⇒ Object
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 |
# File 'lib/rake.rb', line 1681 def define_task(task_class, *args, &block) task_name, arg_names, 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.set_arg_names(arg_names) unless arg_names.empty? task.add_description(@last_description) @last_description = 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.
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 |
# File 'lib/rake.rb', line 1780 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.
1847 1848 1849 1850 1851 1852 1853 1854 1855 |
# File 'lib/rake.rb', line 1847 def in_namespace(name) name ||= generate_name @scope.push(name) ns = NameSpace.new(self, @scope) yield(ns) ns ensure @scope.pop end |
#initialize ⇒ Object
1667 1668 1669 1670 1671 1672 1673 |
# File 'lib/rake.rb', line 1667 def initialize super @tasks = Hash.new @rules = Array.new @scope = Array.new @last_description = 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.
1696 1697 1698 |
# File 'lib/rake.rb', line 1696 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.
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 |
# File 'lib/rake.rb', line 1811 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. Returns a triplet of [task_name, arg_name_list, prerequisites].
1716 1717 1718 1719 1720 1721 1722 1723 |
# File 'lib/rake.rb', line 1716 def resolve_args(args) if args.last.is_a?(Hash) deps = args.pop resolve_args_with_dependencies(args, deps) else resolve_args_without_dependencies(args) end end |
#synthesize_file_task(task_name) ⇒ Object
1709 1710 1711 1712 |
# File 'lib/rake.rb', line 1709 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.
1796 1797 1798 |
# File 'lib/rake.rb', line 1796 def tasks @tasks.values.sort_by { |t| t.name } end |