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.
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.
46 47 48 49 |
# File 'lib/ably/modules/state_machine.rb', line 46 def exception_for_state_change_to(state) = "#{self.class}: Unable to transition from #{current_state} => #{state}" Ably::Exceptions::InvalidStateChange.new(, nil, Ably::Exceptions::Codes::CHANNEL_OPERATION_FAILED_INVALID_CHANNEL_STATE) 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.
40 41 42 |
# File 'lib/ably/modules/state_machine.rb', line 40 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
24 25 26 27 28 29 30 |
# File 'lib/ably/modules/state_machine.rb', line 24 def transition_state(state, *args) unless result = transition_to(state.to_sym, *args) exception = exception_for_state_change_to(state) logger.fatal { "#{self.class}: #{exception.}\n#{caller[0..20].join("\n")}" } end result end |