Sha256: 6b202d9c726344ea1a1a8863cc9bea56cbae746cc9ec68dbf37a308d01de903a

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

require 'state_machines'

module Novel
  class StateMachines
    class SagaStatus
      state_machine initial: :started do
        event :wait do
          transition [:started, :processing] => :waiting
          transition processing_compensation: :waiting_compensation
        end

        event :process do
          transition [:started, :waiting] => :processing
          transition waiting_compensation: :processing_compensation
        end

        # CONTEXT: "fail" reserved for private api of state machine
        event :ruin do
          transition processing: :processing_compensation
        end

        event :complete do
          transition [:processing_compensation, :processing] => :completed
        end
      end

      def self.build(state: nil)
        sm = self.new
        sm.state = state.to_s if state
        sm
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
novel-0.3.0 lib/novel/state_machines/saga_status.rb