Sha256: 9740d509fcc33a887309baf3af8d916b6588912717249d42b6e84326a79eef2b

Contents?: true

Size: 1.51 KB

Versions: 26

Compression:

Stored size: 1.51 KB

Contents

module Foobara
  class Command
    class StateMachine < Foobara::StateMachine
      transitions = %i[
        open_transaction
        cast_and_validate_inputs
        load_records
        validate_records
        validate
        run_execute
        commit_transaction
        succeed
        error
        fail
        reset
      ]

      terminal_states = %i[succeeded errored failed]

      states = %i[
        initialized
        transaction_opened
        inputs_casted_and_validated
        loaded_records
        validated_records
        validated_execution
        executing
        transaction_committed
      ] + terminal_states

      can_fail_states = states - terminal_states

      transition_map = {
        initialized: { open_transaction: :transaction_opened },
        transaction_opened: { cast_and_validate_inputs: :inputs_casted_and_validated },
        inputs_casted_and_validated: { load_records: :loaded_records },
        loaded_records: { validate_records: :validated_records },
        validated_records: { validate: :validated_execution },
        validated_execution: { run_execute: :executing },
        executing: { commit_transaction: :transaction_committed },
        transaction_committed: { succeed: :succeeded },
        terminal_states => { reset: :initialized },
        can_fail_states => {
          error: :errored,
          fail: :failed
        }
      }

      set_transition_map(
        transition_map,
        states:,
        terminal_states:,
        transitions:
      )
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/command/src/state_machine.rb
foobara-0.0.25 projects/command/src/state_machine.rb
foobara-0.0.24 projects/command/src/state_machine.rb
foobara-0.0.23 projects/command/src/state_machine.rb
foobara-0.0.22 projects/command/src/state_machine.rb
foobara-0.0.21 projects/command/src/state_machine.rb
foobara-0.0.20 projects/command/src/state_machine.rb
foobara-0.0.19 projects/command/src/state_machine.rb
foobara-0.0.18 projects/command/src/state_machine.rb
foobara-0.0.17 projects/command/src/state_machine.rb
foobara-0.0.16 projects/command/src/state_machine.rb
foobara-0.0.15 projects/command/src/state_machine.rb
foobara-0.0.14 projects/command/src/state_machine.rb
foobara-0.0.13 projects/command/src/state_machine.rb
foobara-0.0.12 projects/command/src/state_machine.rb
foobara-0.0.11 projects/command/src/state_machine.rb
foobara-0.0.10 projects/command/src/state_machine.rb
foobara-0.0.9 projects/command/src/state_machine.rb
foobara-0.0.8 projects/command/src/state_machine.rb
foobara-0.0.7 projects/command/src/state_machine.rb