module Ably::Modules::StateMachine
Module providing Statesman StateMachine
functionality
Expects method logger to be defined
@api private
Public Class Methods
included(klass)
click to toggle source
# 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
Public Instance Methods
exception_for_state_change_to(state)
click to toggle source
@return [Ably::Exceptions::InvalidStateChange]
# File lib/submodules/ably-ruby/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_state()
click to toggle source
@return [Symbol]
# File lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb, line 40 def previous_state previous_transition.to_state if previous_transition end
previous_transition()
click to toggle source
@return [Statesman History Object]
# File lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb, line 34 def previous_transition history[-2] end
transition_state(state, *args)
click to toggle source
Alternative to Statesman’s transition_to that:
-
log state change failures to {Logger}
@return [void]
# File lib/submodules/ably-ruby/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