Module: Capper::Utils::Multistage

Defined in:
lib/capper/utils/multistage.rb

Instance Method Summary collapse

Instance Method Details

#stage(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/capper/utils/multistage.rb', line 5

def stage(*args, &block)
  if args.size == 0
    return fetch(:current_stage, nil)
  end

  name = args.first
  stages = fetch(:stages, [])

  if stages.include?(name)
    abort "Multiple stages with the same name are not allowed"
  end

  namespace :multistage do
    task(name, {}, &block)
  end

  desc "Set the target stage to `#{name}'."
  task(name) do
    set(:current_stage, name.to_sym)
    find_and_execute_task("multistage:#{name}")
  end

  set(:stages, [stages, name].flatten)
end