Module: Ably::Modules::StateMachine Private
- Included in:
- Realtime::Channel::ChannelStateMachine, Realtime::Connection::ConnectionStateMachine, Realtime::Presence::PresenceStateMachine
- Defined in:
- lib/ably/modules/state_machine.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Module providing Statesman StateMachine functionality
Expects method #logger to be defined
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .included(klass) ⇒ Object private
Instance Method Summary collapse
- #exception_for_state_change_to(state) ⇒ Ably::Exceptions::InvalidStateChange private
- #previous_state ⇒ Symbol private
- #previous_transition ⇒ Statesman History Object private
-
#transition_state(state, *args) ⇒ void
private
Alternative to Statesman’s #transition_to that: * log state change failures to Logger * raise an exception on the Realtime::Channel.
Class Method Details
.included(klass) ⇒ 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.
11 12 13 14 15 16 17 |
# File 'lib/ably/modules/state_machine.rb', line 11 def self.included(klass) klass.class_eval do include Statesman::Machine end klass.extend Ably::Modules::StatesmanMonkeyPatch klass.extend ClassMethods end |
Instance Method Details
#exception_for_state_change_to(state) ⇒ Ably::Exceptions::InvalidStateChange
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.
44 45 46 47 |
# File 'lib/ably/modules/state_machine.rb', line 44 def exception_for_state_change_to(state) = "#{self.class}: Unable to transition from #{current_state} => #{state}" Ably::Exceptions::InvalidStateChange.new(, nil, 80020) end |
#previous_state ⇒ Symbol
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.
39 40 41 |
# File 'lib/ably/modules/state_machine.rb', line 39 def previous_state previous_transition.to_state if previous_transition end |
#previous_transition ⇒ Statesman History 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.
34 35 36 |
# File 'lib/ably/modules/state_machine.rb', line 34 def previous_transition history[-2] end |
#transition_state(state, *args) ⇒ 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.
Alternative to Statesman’s #transition_to that:
-
log state change failures to Logger
-
raise an exception on the Realtime::Channel
24 25 26 27 28 29 30 31 |
# File 'lib/ably/modules/state_machine.rb', line 24 def transition_state(state, *args) unless result = transition_to(state, *args) exception = exception_for_state_change_to(state) object.emit :error, exception logger.fatal "#{self.class}: #{exception.}" end result end |