Class: Ably::Models::ChannelStateChange
- Inherits:
-
Object
- Object
- Ably::Models::ChannelStateChange
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- 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
-
#current ⇒ Connection::STATE
readonly
Current channel state.
-
#previous ⇒ Connection::STATE
readonly
Previous channel state.
-
#reason ⇒ Ably::Models::ErrorInfo
readonly
Object describing the reason for a state change when not initiated by the consumer of the client library.
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#initialize(hash_object) ⇒ ChannelStateChange
constructor
A new instance of ChannelStateChange.
- #to_s ⇒ Object
Methods included from Ably::Modules::ModelCommon
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(hash_object) ⇒ ChannelStateChange
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ably/models/channel_state_change.rb', line 15 def initialize(hash_object) unless (hash_object.keys - [:current, :previous, :reason, :protocol_message]).empty? raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :reason' end @hash_object = { current: hash_object.fetch(:current), previous: hash_object.fetch(:previous), reason: hash_object[:reason], protocol_message: hash_object[:protocol_message] } rescue KeyError => e raise ArgumentError, e end |
Instance Attribute Details
#current ⇒ Connection::STATE (readonly)
12 13 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 |
# File 'lib/ably/models/channel_state_change.rb', line 12 class ChannelStateChange include Ably::Modules::ModelCommon def initialize(hash_object) unless (hash_object.keys - [:current, :previous, :reason, :protocol_message]).empty? raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :reason' end @hash_object = { current: hash_object.fetch(:current), previous: hash_object.fetch(:previous), reason: hash_object[:reason], protocol_message: hash_object[:protocol_message] } rescue KeyError => e raise ArgumentError, e end %w(current previous reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "ChannelStateChange: current state #{current}, previous state #{previous}" end end |
#previous ⇒ Connection::STATE (readonly)
12 13 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 |
# File 'lib/ably/models/channel_state_change.rb', line 12 class ChannelStateChange include Ably::Modules::ModelCommon def initialize(hash_object) unless (hash_object.keys - [:current, :previous, :reason, :protocol_message]).empty? raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :reason' end @hash_object = { current: hash_object.fetch(:current), previous: hash_object.fetch(:previous), reason: hash_object[:reason], protocol_message: hash_object[:protocol_message] } rescue KeyError => e raise ArgumentError, e end %w(current previous reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "ChannelStateChange: current state #{current}, previous state #{previous}" end end |
#reason ⇒ Ably::Models::ErrorInfo (readonly)
12 13 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 |
# File 'lib/ably/models/channel_state_change.rb', line 12 class ChannelStateChange include Ably::Modules::ModelCommon def initialize(hash_object) unless (hash_object.keys - [:current, :previous, :reason, :protocol_message]).empty? raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :reason' end @hash_object = { current: hash_object.fetch(:current), previous: hash_object.fetch(:previous), reason: hash_object[:reason], protocol_message: hash_object[:protocol_message] } rescue KeyError => e raise ArgumentError, e end %w(current previous reason protocol_message).each do |attribute| define_method attribute do @hash_object[attribute.to_sym] end end def to_s "ChannelStateChange: current state #{current}, previous state #{previous}" end end |
Instance Method Details
#to_s ⇒ Object
36 37 38 |
# File 'lib/ably/models/channel_state_change.rb', line 36 def to_s "ChannelStateChange: current state #{current}, previous state #{previous}" end |