class Ably::Models::ChannelStateChange

Contains state change information emitted by {Ably::Rest::Channel} and {Ably::Realtime::Channel} objects.

Public Class Methods

new(hash_object) click to toggle source
# 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

Public Instance Methods

current() click to toggle source

The new current {Ably::Realtime::Channel::STATE}.

@spec RTL2a, RTL2b

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

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

The event that triggered this {Ably::Realtime::Channel::STATE} change.

@spec TH5

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

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

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

@spec RTL2a, RTL2b

@return [Ably::Realtime::Channel::EVENT]

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

@api private

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

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

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

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

@spec RTL2f, TH4

@return [Boolean]

# File lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb, line 70
def resumed
  !!@hash_object[:resumed]
end
Also aliased as: resumed?
resumed?()
Alias for: resumed
to_s() click to toggle source
# 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