Module: Ably::Modules::StateMachine Private

Defined in:
lib/submodules/ably-ruby/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

Instance Method Summary collapse

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/submodules/ably-ruby/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.



42
43
44
45
# File 'lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb', line 42

def exception_for_state_change_to(state)
  error_message = "#{self.class}: Unable to transition from #{current_state} => #{state}"
  Ably::Exceptions::InvalidStateChange.new(error_message, nil, Ably::Exceptions::Codes::CHANNEL_OPERATION_FAILED_INVALID_CHANNEL_STATE)
end

#previous_stateSymbol

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:

  • (Symbol)


37
38
39
# File 'lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb', line 37

def previous_state
  previous_transition.to_state if previous_transition
end

#previous_transitionStatesman 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.

Returns:

  • (Statesman History Object)


32
33
34
# File 'lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb', line 32

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



23
24
25
26
27
28
29
# File 'lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb', line 23

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.message}\n#{caller[0..20].join("\n")}" }
  end
  result
end