Class: EcoRake::Lib::Task::RunnerLaunch

Inherits:
BaseTask show all
Defined in:
lib/eco-rake/lib/task/runner_launch.rb

Constant Summary collapse

FORWARD_RULES =
{
  enviro:   ->(enviro) { "-#{enviro}"      },
  space:    ->(space)  { "-space #{space}" },
  simulate: '-simulate',
  no_email: '-no-email',
  notify:   '-notify'
}.freeze

Constants inherited from EcoRake

VERSION

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.subtask(name, desc = nil, **kargs, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/eco-rake/lib/task/runner_launch.rb', line 25

def subtask(name, desc = nil, **kargs, &block)
  unless task_option&.enum?
    option_reopen(
      :task,
      type:     [],
      desc:     'Target task to run',
      required: true
    )
  end

  EcoRake::Subtask.new(name, desc, **kargs, &block).tap do |subtask|
    raise "Task '#{name}' is already defined" if subtasks.key?(subtask.name)

    option_get(:task).tap do |option|
      option.enum_options.push(subtask.name)
      subtasks[subtask.name] = subtask
    end
  end
end

.subtasksObject



45
46
47
# File 'lib/eco-rake/lib/task/runner_launch.rb', line 45

def subtasks
  @subtasks ||= {}
end

.task_optionObject



21
22
23
# File 'lib/eco-rake/lib/task/runner_launch.rb', line 21

def task_option
  option_get(:task)
end

Instance Method Details

#task(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/eco-rake/lib/task/runner_launch.rb', line 52

def task(*args)
  if (callback = target_subtask.callback)
    instance_exec(*args, &callback)
  elsif respond_to?(target_subtask.command_name, true)
    send(target_subtask.command_name)
  else
    msg = "Undefined method to perform '#{target_subtask.command_name}'"
    raise msg
  end
end