Class: Ably::Models::ConnectionStateChange
- Inherits:
-
Object
- Object
- Ably::Models::ConnectionStateChange
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/ably/models/connection_state_change.rb
Overview
ConnectionStateChange is a class that is emitted by the Realtime::Connection object when a state change occurs
Instance Attribute Summary collapse
-
#current ⇒ Connection::STATE
readonly
Current connection state.
-
#previous ⇒ Connection::STATE
readonly
Previous connection state.
-
#reason ⇒ Ably::Models::ErrorInfo
readonly
Object describing the reason for a state change when not initiated by the consumer of the client library.
-
#retry_in ⇒ Integer
readonly
Time in seconds until the connection will reattempt to connect when in the
:disconnectedor:suspendedstate.
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#initialize(hash_object) ⇒ ConnectionStateChange
constructor
A new instance of ConnectionStateChange.
- #to_s ⇒ Object
Methods included from Ably::Modules::ModelCommon
#==, #[], #as_json, included, #to_json
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(hash_object) ⇒ ConnectionStateChange
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ably/models/connection_state_change.rb', line 17 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 Attribute Details
#current ⇒ Connection::STATE (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ably/models/connection_state_change.rb', line 14 class ConnectionStateChange include Ably::Modules::ModelCommon 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 %w(current previous event retry_in reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "<ConnectionStateChange: current state #{current}, previous state #{previous}>" end end |
#previous ⇒ Connection::STATE (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ably/models/connection_state_change.rb', line 14 class ConnectionStateChange include Ably::Modules::ModelCommon 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 %w(current previous event retry_in reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "<ConnectionStateChange: current state #{current}, previous state #{previous}>" end end |
#reason ⇒ Ably::Models::ErrorInfo (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ably/models/connection_state_change.rb', line 14 class ConnectionStateChange include Ably::Modules::ModelCommon 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 %w(current previous event retry_in reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "<ConnectionStateChange: current state #{current}, previous state #{previous}>" end end |
#retry_in ⇒ Integer (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ably/models/connection_state_change.rb', line 14 class ConnectionStateChange include Ably::Modules::ModelCommon 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 %w(current previous event retry_in reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "<ConnectionStateChange: current state #{current}, previous state #{previous}>" end end |
Instance Method Details
#to_s ⇒ Object
40 41 42 |
# File 'lib/ably/models/connection_state_change.rb', line 40 def to_s "<ConnectionStateChange: current state #{current}, previous state #{previous}>" end |