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

ChannelStateChange is a class that is emitted by the Realtime::Channel object when a state change occurs

Instance Attribute Summary collapse

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.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 17

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 Attribute Details

#currentConnection::STATE (readonly)

Returns Current channel state.

Returns:

  • (Connection::STATE)

    Current channel state



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
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 14

class ChannelStateChange
  include Ably::Modules::ModelCommon

  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

  %w(current previous event reason).each do |attribute|
    define_method attribute do
      @hash_object[attribute.to_sym]
    end
  end

  def resumed
    !!@hash_object[:resumed]
  end
  alias_method :resumed?, :resumed

  # @api private
  def protocol_message
    @hash_object[:protocol_message]
  end

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

#previousConnection::STATE (readonly)

Returns Previous channel state.

Returns:

  • (Connection::STATE)

    Previous channel state



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
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 14

class ChannelStateChange
  include Ably::Modules::ModelCommon

  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

  %w(current previous event reason).each do |attribute|
    define_method attribute do
      @hash_object[attribute.to_sym]
    end
  end

  def resumed
    !!@hash_object[:resumed]
  end
  alias_method :resumed?, :resumed

  # @api private
  def protocol_message
    @hash_object[:protocol_message]
  end

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

#reasonAbly::Models::ErrorInfo (readonly)

Returns Object describing the reason for a state change when not initiated by the consumer of the client library.

Returns:

  • (Ably::Models::ErrorInfo)

    Object describing the reason for a state change when not initiated by the consumer of the client library



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
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 14

class ChannelStateChange
  include Ably::Modules::ModelCommon

  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

  %w(current previous event reason).each do |attribute|
    define_method attribute do
      @hash_object[attribute.to_sym]
    end
  end

  def resumed
    !!@hash_object[:resumed]
  end
  alias_method :resumed?, :resumed

  # @api private
  def protocol_message
    @hash_object[:protocol_message]
  end

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

#resumedBoolean (readonly) Also known as: resumed?

Returns True when a channel is resumed, false when continuity on the channel is no longer provided indicating that the developer is now responsible for recovering lost messages on this channel through other means, such as using the hisory API.

Returns:

  • (Boolean)

    True when a channel is resumed, false when continuity on the channel is no longer provided indicating that the developer is now responsible for recovering lost messages on this channel through other means, such as using the hisory API



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
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 14

class ChannelStateChange
  include Ably::Modules::ModelCommon

  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

  %w(current previous event reason).each do |attribute|
    define_method attribute do
      @hash_object[attribute.to_sym]
    end
  end

  def resumed
    !!@hash_object[:resumed]
  end
  alias_method :resumed?, :resumed

  # @api private
  def protocol_message
    @hash_object[:protocol_message]
  end

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

Instance Method Details

#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.



46
47
48
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb', line 46

def protocol_message
  @hash_object[:protocol_message]
end

#to_sObject



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

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