Module: Trailblazer::Core::Utils::DefSteps

Defined in:
lib/trailblazer/core/utils/def_steps.rb

Overview

Helpers to quickly create steps and tasks.

Class Method Summary collapse

Class Method Details

.def_steps(*names) ⇒ Object

Creates a module with one step method for each name.

Examples:

extend T.def_steps(:create, :save)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/trailblazer/core/utils/def_steps.rb', line 9

def self.def_steps(*names)
  Module.new do
    module_function

    names.each do |name|
      define_method(name) do |ctx, **|
        ctx[:seq] << name
        ctx.key?(name) ? ctx[name] : true
      end
    end
  end
end

.def_task(name) ⇒ Object

Creates a method instance with a task interface.

Examples:

task task: T.def_task(:create)


26
27
28
# File 'lib/trailblazer/core/utils/def_steps.rb', line 26

def self.def_task(name)
  def_tasks(name).method(name)
end

.def_tasks(*names) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trailblazer/core/utils/def_steps.rb', line 30

def self.def_tasks(*names)
  Module.new do
    module_function

    names.each do |name|
      define_method(name) do |(ctx, flow_options), **|
        ctx[:seq] << name
        signal = ctx.key?(name) ? ctx[name] : Activity::Right

        return signal, [ctx, flow_options]
      end
    end
  end
end