Sha256: 9740d509fcc33a887309baf3af8d916b6588912717249d42b6e84326a79eef2b

Contents?: true

Size: 1.51 KB

Versions: 27

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

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/command/src/state_machine.rb
foobara-0.0.6 projects/command/src/state_machine.rb
foobara-0.0.5 projects/command/src/state_machine.rb
foobara-0.0.4 projects/command/src/state_machine.rb
foobara-0.0.3 projects/command/src/state_machine.rb
foobara-0.0.2 projects/command/src/state_machine.rb
foobara-0.0.1 projects/command/src/state_machine.rb