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.



44
45
46
47
# File 'lib/ably/modules/state_machine.rb', line 44

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, 80020)
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)


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

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:



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.message}"
  end
  result
end