Module: ActiveSaga::DSL::Steps

Included in:
Workflow
Defined in:
lib/active_saga/dsl/steps.rb

Defined Under Namespace

Classes: StepDefinition

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



69
70
71
# File 'lib/active_saga/dsl/steps.rb', line 69

def self.extended(base)
  base.class_attribute :_as_steps, instance_writer: false, default: []
end

Instance Method Details

#inherited(subclass) ⇒ Object



73
74
75
76
# File 'lib/active_saga/dsl/steps.rb', line 73

def inherited(subclass)
  super
  subclass._as_steps = _as_steps.map(&:dup)
end

#step(name, **options) ⇒ Object



87
88
89
# File 'lib/active_saga/dsl/steps.rb', line 87

def step(name, **options)
  register_step(:method, name, nil, options)
end

#step_definition(name) ⇒ Object



82
83
84
85
# File 'lib/active_saga/dsl/steps.rb', line 82

def step_definition(name)
  steps.find { |definition| definition.name == name.to_sym } ||
    raise(ActiveSaga::Errors::InvalidStep, "Unknown step: #{name}")
end

#stepsObject



78
79
80
# File 'lib/active_saga/dsl/steps.rb', line 78

def steps
  _as_steps
end

#task(name, handler = nil, **options, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/active_saga/dsl/steps.rb', line 91

def task(name, handler = nil, **options, &block)
  if handler && block
    raise ActiveSaga::Errors::InvalidStep, "Provide a Task class or a block, not both"
  end

  callable = handler || block
  style = if block
    :block
  elsif handler.is_a?(Class) && handler <= ActiveSaga::Task
    :task
  elsif handler.respond_to?(:call)
    :callable
  else
    raise ActiveSaga::Errors::InvalidStep, "Task handler must be a Task subclass, callable, or block"
  end

  step_options = if handler.is_a?(Class) && handler <= ActiveSaga::Task
    handler.async_options.deep_merge(options)
  else
    options
  end

  register_step(style, name, callable, step_options)
end

#wait_for_signal(name, **options) ⇒ Object



116
117
118
# File 'lib/active_saga/dsl/steps.rb', line 116

def wait_for_signal(name, **options)
  register_step(:wait, name, nil, options)
end