Module: Ably::Modules::StateMachine Private

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/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)
  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)


40
41
42
# File 'lib/ably/modules/state_machine.rb', line 40

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)


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