Sha256: 222586957d4f94d838e38a8d06bc5178fbf03a0683f0b361097d7d0a84f53d40

Contents?: true

Size: 1.8 KB

Versions: 95

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module Spree
  module Core
    class StateMachines
      # Shipments' state machine
      #
      # for each event the following instance methods are dynamically implemented:
      #   #<event_name>
      #   #<event_name>!
      #   #can_<event_name>?
      #
      # for each state the following instance methods are implemented:
      #   #<state_name>?
      #
      module Shipment
        extend ActiveSupport::Concern

        included do
          state_machine initial: :pending, use_transactions: false do
            event :ready do
              transition from: :pending, to: :shipped, if: :can_transition_from_pending_to_shipped?
              transition from: :pending, to: :ready, if: :can_transition_from_pending_to_ready?
            end

            event :pend do
              transition from: :ready, to: :pending
            end

            event :ship do
              transition from: [:ready, :canceled], to: :shipped
            end
            after_transition to: :shipped, do: :after_ship

            event :cancel do
              transition to: :canceled, from: [:pending, :ready]
            end
            after_transition to: :canceled, do: :after_cancel

            event :resume do
              transition from: :canceled, to: :ready, if: :can_transition_from_canceled_to_ready?
              transition from: :canceled, to: :pending
            end
            after_transition from: :canceled, to: [:pending, :ready, :shipped], do: :after_resume

            after_transition do |shipment, transition|
              shipment.state_changes.create!(
                previous_state: transition.from,
                next_state:     transition.to,
                name:           'shipment'
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
solidus_core-4.5.1 app/models/spree/core/state_machines/shipment.rb
solidus_core-4.5.0 app/models/spree/core/state_machines/shipment.rb
solidus_core-4.3.6 lib/spree/core/state_machines/shipment.rb
solidus_core-4.2.5 lib/spree/core/state_machines/shipment.rb
solidus_core-4.1.6 lib/spree/core/state_machines/shipment.rb
solidus_core-4.4.2 lib/spree/core/state_machines/shipment.rb
solidus_core-4.4.1 lib/spree/core/state_machines/shipment.rb
solidus_core-4.4.0 lib/spree/core/state_machines/shipment.rb
solidus_core-4.3.4 lib/spree/core/state_machines/shipment.rb
solidus_core-4.2.4 lib/spree/core/state_machines/shipment.rb
solidus_core-4.1.5 lib/spree/core/state_machines/shipment.rb
solidus_core-4.3.3 lib/spree/core/state_machines/shipment.rb
solidus_core-4.3.2 lib/spree/core/state_machines/shipment.rb
solidus_core-4.1.4 lib/spree/core/state_machines/shipment.rb
solidus_core-4.3.1 lib/spree/core/state_machines/shipment.rb
solidus_core-4.3.0 lib/spree/core/state_machines/shipment.rb
solidus_core-4.2.3 lib/spree/core/state_machines/shipment.rb
solidus_core-4.1.3 lib/spree/core/state_machines/shipment.rb
solidus_core-4.0.4 lib/spree/core/state_machines/shipment.rb
solidus_core-3.4.6 lib/spree/core/state_machines/shipment.rb