Class: Ably::Models::ConnectionStateChange

Inherits:
Object
  • Object
show all
Includes:
Ably::Modules::ModelCommon
Defined in:
lib/ably/models/connection_state_change.rb

Overview

Contains ConnectionState change information emitted by the Realtime::Connection object.

Instance Attribute Summary

Attributes included from Ably::Modules::ModelCommon

#hash

Instance Method Summary collapse

Methods included from Ably::Modules::ModelCommon

#==, #[], #as_json, included, #to_json

Methods included from Ably::Modules::MessagePack

#to_msgpack

Constructor Details

#initialize(hash_object) ⇒ ConnectionStateChange

Returns a new instance of ConnectionStateChange.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File '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

Instance Method Details

#currentAbly::Realtime::Connection::STATE



30
31
32
# File 'lib/ably/models/connection_state_change.rb', line 30

def current
  @hash_object[:current]
end

#eventAbly::Realtime::Connection::STATE

The event that triggered this Realtime::Connection::EVENT change.



40
41
42
# File 'lib/ably/models/connection_state_change.rb', line 40

def event
  @hash_object[:event]
end

#previousAbly::Realtime::Connection::STATE

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



51
52
53
# File 'lib/ably/models/connection_state_change.rb', line 51

def previous
  @hash_object[:previous]
end

#protocol_messageObject



75
76
77
# File 'lib/ably/models/connection_state_change.rb', line 75

def protocol_message
  @hash_object[:protocol_message]
end

#reasonAbly::Models::ErrorInfo?

An ErrorInfo object containing any information relating to the transition.

Returns:



61
62
63
# File 'lib/ably/models/connection_state_change.rb', line 61

def reason
  @hash_object[:reason]
end

#retry_inInteger

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

Returns:

  • (Integer)


71
72
73
# File 'lib/ably/models/connection_state_change.rb', line 71

def retry_in
  @hash_object[:retry_in]
end

#to_sObject



79
80
81
# File 'lib/ably/models/connection_state_change.rb', line 79

def to_s
  "<ConnectionStateChange: current state #{current}, previous state #{previous}>"
end