Module: Ably::Modules::UsesStateMachine
- Extended by:
- Forwardable
- Included in:
- Realtime::Channel, Realtime::Connection, Realtime::Models::NilChannel, Realtime::Presence
- Defined in:
- lib/ably/modules/uses_state_machine.rb
Overview
Mixing module that assists with Statemans State Machine state transitions and maintaining state of this object’s #state.
Expects:
- @state_machine is set to the StateMachine
- StateEmitter is included in the object
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#previous_state ⇒ STATE?
readonly
private
The previous state for this connection.
-
#state_history ⇒ Array<Hash>
readonly
private
All previous states including the current state in date ascending order with Hash properties :state, :metadata, :transitioned_at.
Instance Method Summary collapse
-
#synchronize_state_with_statemachine(*args) ⇒ Object
private
Provides an internal method for this object’s state to match the StateMachine’s current state.
-
#transition_state_machine(new_state, emit_params = {}) ⇒ Boolean
private
Call #transition_to on the StateMachine.
-
#transition_state_machine!(new_state, emit_params = {}) ⇒ void
private
Call #transition_to! on the StateMachine An exception wil be raised if new_state cannot be transitioned to by state machine.
Instance Attribute Details
#previous_state ⇒ STATE? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The previous state for this connection.
40 41 42 43 44 |
# File 'lib/ably/modules/uses_state_machine.rb', line 40 def previous_state if state_machine.previous_state STATE(state_machine.previous_state) end end |
#state_history ⇒ Array<Hash> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns All previous states including the current state in date ascending order with Hash properties :state, :metadata, :transitioned_at.
49 50 51 52 53 54 55 56 57 |
# File 'lib/ably/modules/uses_state_machine.rb', line 49 def state_history state_machine.history.map do |transition| { state: STATE(transition.to_state), metadata: transition., transitioned_at: transition.created_at } end end |
Instance Method Details
#synchronize_state_with_statemachine(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Provides an internal method for this object’s state to match the StateMachine’s current state. The current object’s state will be changed to the StateMachine state and will emit an event
32 33 34 35 |
# File 'lib/ably/modules/uses_state_machine.rb', line 32 def synchronize_state_with_statemachine(*args) log_state_machine_state_change change_state state_machine.current_state, state_machine.last_transition. end |
#transition_state_machine(new_state, emit_params = {}) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Call #transition_to on the StateMachine
16 17 18 |
# File 'lib/ably/modules/uses_state_machine.rb', line 16 def transition_state_machine(new_state, emit_params = {}) state_machine.transition_state(new_state, emit_object(new_state, emit_params)) end |
#transition_state_machine!(new_state, emit_params = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Call #transition_to! on the StateMachine An exception wil be raised if new_state cannot be transitioned to by state machine
25 26 27 |
# File 'lib/ably/modules/uses_state_machine.rb', line 25 def transition_state_machine!(new_state, emit_params = {}) state_machine.transition_to!(new_state, emit_object(new_state, emit_params)) end |