Class: StateMachine::SendEventTransition

Inherits:
Transition
  • Object
show all
Defined in:
lib/motion-state-machine/transition.rb

Overview

This is kind of the ‘standard’ transition. It is created when supplying the :on option in the state machine definition.

If armed, the transition is triggered when sending an event to the state machine by calling Base#event with the event’s symbol as parameter. Sending the same event symbol while not armed will just ignore the event.

Note that you should call the Base#event method from the same queue / thread where the state machine was started.

Examples:


state_machine.when :sleeping do |state|
  state.transition_to :awake, on: :foo
end

state_machine.event :foo
  # => state machine goes to :awake state

Instance Attribute Summary

Attributes inherited from Transition

#destination_state, #event_trigger_value, #options, #source_state, #state_machine

Instance Method Summary collapse

Methods inherited from Transition

#allowed?, #inspect, make, types

Constructor Details

#initialize(options) ⇒ SendEventTransition

Returns a new instance of SendEventTransition.



280
281
282
283
# File 'lib/motion-state-machine/transition.rb', line 280

def initialize(options)
  super(options)
  unarm
end

Instance Method Details

#armObject



289
290
291
# File 'lib/motion-state-machine/transition.rb', line 289

def arm
  state_machine.register_event_handler event_trigger_value, self
end

#event_descriptionObject



285
286
287
# File 'lib/motion-state-machine/transition.rb', line 285

def event_description
  "after #{event_trigger_value}"
end

#unarmObject



293
294
295
# File 'lib/motion-state-machine/transition.rb', line 293

def unarm
  state_machine.register_event_handler event_trigger_value, nil
end