around_transition do |order, transition, block| puts "Starting transition from #{transition.from}" block.call puts "Finished transition to #{transition.to}" end event :submit do transition :new => :payment_waiting end event :payment_received do transition :payment_waiting => :waiting_for_processing end event :payment_failed do transition :payment_waiting => :payment_failed
do transition :payment_waiting => :payment_failed end event :retry_payment do transition :payment_failed => :payment_waiting end event :process do transition :waiting_for_processing => :waiting_for_shipping end event :ship do transition :waiting_for_shipping => :shipped end after_transition :on => :ship, :do => :notify_customer
transitions, first matching is taken event :cancel do transition :waiting_for_processing => :canceled transition :waiting_for_shipping => :canceled transition :shipped => :waiting_for_return end event :return_shipment_received do transition :waiting_for_return => :canceled end end def notify_customer puts "Your package has been shipped! :shipit:" end end
let validTransitions: [P.StateType: [P.StateType]] private var _state:P.StateType{ didSet { delegate.didTransitionFrom(oldValue, to:_state) } } var state:P.StateType { get{ return _state } set{ // Can't be an observer because we need the option to CONDITIONALLY set state attemptTransitionTo(newValue) }
} set{ // Can't be an observer because we need the option to CONDITIONALLY set state attemptTransitionTo(newValue) } } init(initialState:P.StateType, delegate:P, validTransitions: [P.StateTy [P.StateType]]) { _state = initialState //set the primitive to avoid calling the delegate. self.validTransitions = validTransitions