Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support or ConnectionStateMachine and ChannelStateMachine
Fixes #52
- Loading branch information
1 parent
1a5fffa
commit aa05eba
Showing
19 changed files
with
343 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Ably::Models | ||
# ChannelStateChange is a class that is emitted by the {Ably::Realtime::Channel} object | ||
# when a state change occurs | ||
# | ||
# @!attribute [r] current | ||
# @return [Connection::STATE] Current connection state | ||
# @!attribute [r] previous | ||
# @return [Connection::STATE] Previous connection 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 | ||
# | ||
class ChannelStateChange | ||
include Ably::Modules::ModelCommon | ||
|
||
def initialize(hash_object) | ||
unless (hash_object.keys - [:current, :previous, :reason]).empty? | ||
raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :reason' | ||
end | ||
|
||
@hash_object = { | ||
current: hash_object.fetch(:current), | ||
previous: hash_object.fetch(:previous), | ||
retry_in: hash_object[:retry_in], | ||
reason: hash_object[:reason] | ||
} | ||
rescue KeyError => e | ||
raise ArgumentError, e | ||
end | ||
|
||
%w(current previous reason).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 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Ably::Models | ||
# ConnectionStateChange is a class that is emitted by the {Ably::Realtime::Connection} object | ||
# when a state change occurs | ||
# | ||
# @!attribute [r] current | ||
# @return [Connection::STATE] Current connection state | ||
# @!attribute [r] previous | ||
# @return [Connection::STATE] Previous connection state | ||
# @!attribute [r] retry_in | ||
# @return [Integer] Time in seconds until the connection will reattempt to connect when in the +:disconnected+ or +:suspended+ 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 | ||
# | ||
class ConnectionStateChange | ||
include Ably::Modules::ModelCommon | ||
|
||
def initialize(hash_object) | ||
unless (hash_object.keys - [:current, :previous, :retry_in, :reason]).empty? | ||
raise ArgumentError, 'Invalid attributes, expecting :current, :previous, :retry_in, :reason' | ||
end | ||
|
||
@hash_object = { | ||
current: hash_object.fetch(:current), | ||
previous: hash_object.fetch(:previous), | ||
retry_in: hash_object[:retry_in], | ||
reason: hash_object[:reason] | ||
} | ||
rescue KeyError => e | ||
raise ArgumentError, e | ||
end | ||
|
||
%w(current previous retry_in reason).each do |attribute| | ||
define_method attribute do | ||
@hash_object[attribute.to_sym] | ||
end | ||
end | ||
|
||
def to_s | ||
"ConnectionStateChange: current state #{current}, previous state #{previous}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.