Class: Ably::Models::ChannelStateChange
- Inherits:
-
Object
- Object
- Ably::Models::ChannelStateChange
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/ably/models/channel_state_change.rb
Overview
Contains state change information emitted by Rest::Channel and Realtime::Channel objects.
Instance Attribute Summary
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#current ⇒ Ably::Realtime::Channel::STATE
The new current Realtime::Channel::STATE.
-
#event ⇒ Ably::Realtime::Channel::STATE
The event that triggered this Realtime::Channel::STATE change.
-
#initialize(hash_object) ⇒ ChannelStateChange
constructor
A new instance of ChannelStateChange.
-
#previous ⇒ Ably::Realtime::Channel::EVENT
The previous state.
- #protocol_message ⇒ Object private
-
#reason ⇒ Ably::Models::ErrorInfo?
An ErrorInfo object containing any information relating to the transition.
-
#resumed ⇒ Boolean
(also: #resumed?)
Indicates whether message continuity on this channel is preserved, see Nonfatal channel errors for more info.
- #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) ⇒ ChannelStateChange
Returns a new instance of ChannelStateChange.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ably/models/channel_state_change.rb', line 7 def initialize(hash_object) unless (hash_object.keys - [:current, :previous, :event, :reason, :resumed, :protocol_message]).empty? raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :event, :reason, :resumed' end @hash_object = { current: hash_object.fetch(:current), previous: hash_object.fetch(:previous), event: hash_object[:event], reason: hash_object[:reason], protocol_message: hash_object[:protocol_message], resumed: hash_object[:resumed] } rescue KeyError => e raise ArgumentError, e end |
Instance Method Details
#current ⇒ Ably::Realtime::Channel::STATE
The new current Realtime::Channel::STATE.
30 31 32 |
# File 'lib/ably/models/channel_state_change.rb', line 30 def current @hash_object[:current] end |
#event ⇒ Ably::Realtime::Channel::STATE
The event that triggered this Realtime::Channel::STATE change.
50 51 52 |
# File 'lib/ably/models/channel_state_change.rb', line 50 def event @hash_object[:event] end |
#previous ⇒ Ably::Realtime::Channel::EVENT
The previous state. For the Realtime::Channel::EVENT(:update) event, this is equal to the current Realtime::Channel::STATE.
40 41 42 |
# File 'lib/ably/models/channel_state_change.rb', line 40 def previous @hash_object[:previous] end |
#protocol_message ⇒ 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.
76 77 78 |
# File 'lib/ably/models/channel_state_change.rb', line 76 def @hash_object[:protocol_message] end |
#reason ⇒ Ably::Models::ErrorInfo?
An ErrorInfo object containing any information relating to the transition.
60 61 62 |
# File 'lib/ably/models/channel_state_change.rb', line 60 def reason @hash_object[:reason] end |
#resumed ⇒ Boolean Also known as: resumed?
Indicates whether message continuity on this channel is preserved, see Nonfatal channel errors for more info.
70 71 72 |
# File 'lib/ably/models/channel_state_change.rb', line 70 def resumed !!@hash_object[:resumed] end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/ably/models/channel_state_change.rb', line 80 def to_s "<ChannelStateChange: current state #{current}, previous state #{previous}>" end |