lib/ably/models/channel_state_change.rb in ably-1.2.2 vs lib/ably/models/channel_state_change.rb in ably-1.2.3
- old
+ new
@@ -1,18 +1,8 @@
module Ably::Models
- # ChannelStateChange is a class that is emitted by the {Ably::Realtime::Channel} object
- # when a state change occurs
+ # Contains state change information emitted by {Ably::Rest::Channel} and {Ably::Realtime::Channel} objects.
#
- # @!attribute [r] current
- # @return [Connection::STATE] Current channel state
- # @!attribute [r] previous
- # @return [Connection::STATE] Previous channel state
- # @!attribute [r] reason
- # @return [Ably::Models::ErrorInfo] Object describing the reason for a state change when not initiated by the consumer of the client library
- # @!attribute [r] resumed
- # @return [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
- #
class ChannelStateChange
include Ably::Modules::ModelCommon
def initialize(hash_object)
unless (hash_object.keys - [:current, :previous, :event, :reason, :resumed, :protocol_message]).empty?
@@ -29,15 +19,55 @@
}
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
+ # The new current {Ably::Realtime::Channel::STATE}.
+ #
+ # @spec RTL2a, RTL2b
+ #
+ # @return [Ably::Realtime::Channel::STATE]
+ #
+ def current
+ @hash_object[:current]
end
+ # 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]
+ #
+ def previous
+ @hash_object[:previous]
+ end
+
+ # The event that triggered this {Ably::Realtime::Channel::STATE} change.
+ #
+ # @spec TH5
+ #
+ # @return [Ably::Realtime::Channel::STATE]
+ #
+ def event
+ @hash_object[:event]
+ end
+
+ # An {Ably::Models::ErrorInfo} object containing any information relating to the transition.
+ #
+ # @spec RTL2e, TH3
+ #
+ # @return [Ably::Models::ErrorInfo, nil]
+ #
+ def reason
+ @hash_object[:reason]
+ end
+
+ # Indicates whether message continuity on this channel is preserved, see Nonfatal channel errors for more info.
+ #
+ # @spec RTL2f, TH4
+ #
+ # @return [Boolean]
+ #
def resumed
!!@hash_object[:resumed]
end
alias_method :resumed?, :resumed