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
- tasks_in_scope
| [RW] | last_description | Track the last comment made in the Rakefile. |
[ show source ]
# File lib/rake.rb, line 1690
1690: def initialize
1691: super
1692: @tasks = Hash.new
1693: @rules = Array.new
1694: @scope = Array.new
1695: @last_description = nil
1696: end
Find a matching task for task_name.
[ show source ]
# File lib/rake.rb, line 1724
1724: def [](task_name, scopes=nil)
1725: task_name = task_name.to_s
1726: self.lookup(task_name, scopes) or
1727: enhance_with_matching_rule(task_name) or
1728: synthesize_file_task(task_name) or
1729: fail "Don't know how to build task '#{task_name}'"
1730: end
Clear all tasks in this application.
[ show source ]
# File lib/rake.rb, line 1833
1833: def clear
1834: @tasks.clear
1835: @rules.clear
1836: end
[ show source ]
# File lib/rake.rb, line 1698
1698: def create_rule(*args, &block)
1699: pattern, arg_names, deps = resolve_args(args)
1700: pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
1701: @rules << [pattern, deps, block]
1702: end
Return the list of scope names currently active in the task manager.
[ show source ]
# File lib/rake.rb, line 1873
1873: def current_scope
1874: @scope.dup
1875: end
[ show source ]
# File lib/rake.rb, line 1704
1704: def define_task(task_class, *args, &block)
1705: task_name, arg_names, deps = resolve_args(args)
1706: task_name = task_class.scope_name(@scope, task_name)
1707: deps = [deps] unless deps.respond_to?(:to_ary)
1708: deps = deps.collect {|d| d.to_s }
1709: task = intern(task_class, task_name)
1710: task.set_arg_names(arg_names) unless arg_names.empty?
1711: task.add_description(@last_description)
1712: @last_description = nil
1713: task.enhance(deps, &block)
1714: task
1715: 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 1803
1803: def enhance_with_matching_rule(task_name, level=0)
1804: fail Rake::RuleRecursionOverflowError,
1805: "Rule Recursion Too Deep" if level >= 16
1806: @rules.each do |pattern, extensions, block|
1807: if md = pattern.match(task_name)
1808: task = attempt_rule(task_name, extensions, block, level)
1809: return task if task
1810: end
1811: end
1812: nil
1813: rescue Rake::RuleRecursionOverflowError => ex
1814: ex.add_target(task_name)
1815: fail ex
1816: 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 1879
1879: def in_namespace(name)
1880: name ||= generate_name
1881: @scope.push(name)
1882: ns = NameSpace.new(self, @scope)
1883: yield(ns)
1884: ns
1885: ensure
1886: @scope.pop
1887: 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 1719
1719: def intern(task_class, task_name)
1720: @tasks[task_name.to_s] ||= task_class.new(task_name, self)
1721: 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 1843
1843: def lookup(task_name, initial_scope=nil)
1844: initial_scope ||= @scope
1845: task_name = task_name.to_s
1846: if task_name =~ /^rake:/
1847: scopes = []
1848: task_name = task_name.sub(/^rake:/, '')
1849: elsif task_name =~ /^(\^+)/
1850: scopes = initial_scope[0, initial_scope.size - $1.size]
1851: task_name = task_name.sub(/^(\^+)/, '')
1852: else
1853: scopes = initial_scope
1854: end
1855: lookup_in_scope(task_name, scopes)
1856: end
Resolve the arguments for a task/rule. Returns a triplet of [task_name, arg_name_list, prerequisites].
[ show source ]
# File lib/rake.rb, line 1739
1739: def resolve_args(args)
1740: if args.last.is_a?(Hash)
1741: deps = args.pop
1742: resolve_args_with_dependencies(args, deps)
1743: else
1744: resolve_args_without_dependencies(args)
1745: end
1746: end
[ show source ]
# File lib/rake.rb, line 1732
1732: def synthesize_file_task(task_name)
1733: return nil unless File.exist?(task_name)
1734: define_task(Rake::FileTask, task_name)
1735: end
List of all defined tasks in this application.
[ show source ]
# File lib/rake.rb, line 1819
1819: def tasks
1820: @tasks.values.sort_by { |t| t.name }
1821: end
List of all the tasks defined in the given scope (and its sub-scopes).
[ show source ]
# File lib/rake.rb, line 1825
1825: def tasks_in_scope(scope)
1826: prefix = scope.join(":")
1827: tasks.select { |t|
1828: /^#{prefix}:/ =~ t.name
1829: }
1830: end