Module: Presenters::Statemachine::StateTransitions

Defined in:
app/models/concerns/presenters/statemachine.rb

Overview

State transitions are common across all of the statemachines.

Class Method Summary collapse

Class Method Details

.inject(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/concerns/presenters/statemachine.rb', line 6

def self.inject(base)
  base.instance_eval do
    event :take_default_path, human_name: 'Manual Transfer' do
      transition pending: :passed
      transition started: :passed
    end

    event :transfer do
      transition %i[pending started] => :passed
    end

    event :cancel do
      transition %i[pending started passed] => :cancelled
    end

    # We use `fail_labware` here as `fail` is defined on Object (its an alias for `raise`)
    # Statemachines ends up throwing a warning, which while we can disable, we're probably
    # safer avoiding the conflict, especially as we don't actually call these methods directly
    # anyway.
    event :fail_labware, human_name: 'Fail' do
      transition %i[pending started passed] => :failed
    end
  end
end