class Ably::Models::ConnectionStateChange

Contains {Ably::Models::ConnectionState} change information emitted by the {Ably::Realtime::Connection} object.

Public Class Methods

new(hash_object) click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 7
def initialize(hash_object)
  unless (hash_object.keys - [:current, :previous, :event, :retry_in, :reason, :protocol_message]).empty?
    raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :event, :retry_in, :reason'
  end

  @hash_object = {
    current: hash_object.fetch(:current),
    previous: hash_object.fetch(:previous),
    event: hash_object[:event],
    retry_in: hash_object[:retry_in],
    reason: hash_object[:reason],
    protocol_message: hash_object[:protocol_message]
  }
rescue KeyError => e
  raise ArgumentError, e
end

Public Instance Methods

current() click to toggle source

The new {Ably::Realtime::Connection::STATE}.

@spec TA2

@return [Ably::Realtime::Connection::STATE]

# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 30
def current
  @hash_object[:current]
end
event() click to toggle source

The event that triggered this {Ably::Realtime::Connection::EVENT} change.

@spec TA5

@return [Ably::Realtime::Connection::STATE]

# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 40
def event
  @hash_object[:event]
end
previous() click to toggle source

The previous {Ably::Models::Connection::STATE}. For the {Ably::Models::Connection::EVENT} UPDATE event, this is equal to the current {Ably::Models::Connection::STATE}.

@spec TA2

@return [Ably::Realtime::Connection::STATE]

# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 51
def previous
  @hash_object[:previous]
end
protocol_message() click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 75
def protocol_message
  @hash_object[:protocol_message]
end
reason() click to toggle source

An {Ably::Models::ErrorInfo} object containing any information relating to the transition.

@spec RTN4f, TA3

@return [Ably::Models::ErrorInfo, nil]

# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 61
def reason
  @hash_object[:reason]
end
retry_in() click to toggle source

Duration in milliseconds, after which the client retries a connection where applicable.

@spec RTN14d, TA2

@return [Integer]

# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 71
def retry_in
  @hash_object[:retry_in]
end
to_s() click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb, line 79
def to_s
  "<ConnectionStateChange: current state #{current}, previous state #{previous}>"
end