Module: Mattock::ConfigurableTask::ClassMethods

Defined in:
lib/mattock/task.rb

Instance Method Summary collapse

Instance Method Details

#default_taskname(name) ⇒ Object



20
21
22
# File 'lib/mattock/task.rb', line 20

def default_taskname(name)
  setting(:task_name, name)
end

#define_task(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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