Class: Ably::Models::ChannelStateChange

Inherits:
Object
  • Object
show all
Includes:
Ably::Modules::ModelCommon
Defined in:
lib/submodules/ably-ruby/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

#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) ⇒ 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/submodules/ably-ruby/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

#currentAbly::Realtime::Channel::STATE

The new current Realtime::Channel::STATE.

Returns:

  • (Ably::Realtime::Channel::STATE)


30
31
32
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 30

def current
  @hash_object[:current]
end

#eventAbly::Realtime::Channel::STATE

The event that triggered this Realtime::Channel::STATE change.

Returns:

  • (Ably::Realtime::Channel::STATE)


50
51
52
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 50

def event
  @hash_object[:event]
end

#previousAbly::Realtime::Channel::EVENT

The previous state. For the Realtime::Channel::EVENT(:update) event, this is equal to the current Realtime::Channel::STATE.

Returns:

  • (Ably::Realtime::Channel::EVENT)


40
41
42
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 40

def previous
  @hash_object[:previous]
end

#protocol_messageObject

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/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 76

def protocol_message
  @hash_object[:protocol_message]
end

#reasonAbly::Models::ErrorInfo?

An ErrorInfo object containing any information relating to the transition.

Returns:



60
61
62
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 60

def reason
  @hash_object[:reason]
end

#resumedBoolean Also known as: resumed?

Indicates whether message continuity on this channel is preserved, see Nonfatal channel errors for more info.

Returns:

  • (Boolean)


70
71
72
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 70

def resumed
  !!@hash_object[:resumed]
end

#to_sObject



80
81
82
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 80

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