module Rake::DSL

Private Instance Methods

group_task(*args, &block) click to toggle source
# File lib/rake/namespace_group/dsl.rb, line 10
def group_task(*args, &block)
  Rake::GroupTask.define_task(*args, &block)
end
namespace_group(name=nil, options={}) { || ... } click to toggle source

Create a new rake namespace and use it for evaluating the given block. Returns a NameSpace object that can be used to lookup tasks defined in the namespace. It also creates a parent level task to execute all tasks defined in this namespace.

Example:

# File lib/rake/namespace_group/dsl.rb, line 25
def namespace_group(name=nil, options={}, &block)
  if options.is_a?(Symbol) or options.is_a?(Array)
    options = { :arguments => options }
  end

  options[:arguments] ||= []
  options[:all] ||= false
  options[:keep_going] ||= true
  options[:exclude] ||= []

  ns_name = options[:namespace] || name
  ns = namespace(ns_name) do
    if block_given?
      (class << self; self; end).send :alias_method, :task, :group_task
      yield
      (class << self; self; end).send :alias_method, :task, :orig_task
    end
  end
  scope = ns.scope

  desc options[:desc] || "Execute all tasks in group #{ns_name}"
  task ns_name, options[:arguments] do |_self, args|
    tasklist = Rake.application.tasks_in_scope(scope)
    exception_list = GroupedError.new(ns_name)
    tasklist.each do |task|
      task_name = task.name.gsub(Regexp.new("^#{ns_name}:"), '')
      if options[:all] or task.is_a?(Rake::GroupTask)
        skip = false
        [options[:exclude]].flatten.each do |excl|
          if excl.is_a?(Regexp) and task_name =~ excl
            skip = true
          elsif excl.is_a?(String) and task_name == excl
            skip = true
          end
        end
        next if skip

        begin
          task.invoke(*args)
        rescue Exception => ex
          exception_list.add_exception(task, ex)
          unless options[:keep_going]
            raise ex
          end
        end
      end
    end
    if exception_list.has_exceptions?
      raise exception_list
    end
  end
end