module Mattock::ConfigurableTask::ClassMethods

Public Instance Methods

default_taskname(name) click to toggle source
# File lib/mattock/task.rb, line 20
def default_taskname(name)
  setting(:task_name, name)
end
define_task(*args) { |t| ... } click to toggle source
# File lib/mattock/task.rb, line 24
def define_task(*args)
  configs = args.take_while{|arg| Calibrate::Configurable === arg}
  extracted_task_args = args[configs.length..-1]
  if extracted_task_args.any?{|arg| Calibrate::Configurable === arg}
    raise "Mattock::Task classes should be created with parent configs, then Rake task args"
  end

  if extracted_task_args.empty?
    extracted_task_args = [default_value_for(:task_name)]
  end

  task = ::Rake.application.define_task(self, *extracted_task_args) do |task, args|
    task.finalize_configuration
    task.action(args)
  end

  #XXX ?? Dilemma: this prevents an existing task action from being
  #enriched with this one, but not v/v - it also doesn't prevent double
  #-definition of this task...
  unless self === task
    raise "Task already defined for #{task.name} - attempted to redefine with #{self.name}"
  end

  task.setup_deferred
  task.setup_cascade(*configs) do |t|
    t.task_name = task.name
    t.task_args = extracted_task_args

    yield(t) if block_given?
  end
  return task
end