-
Notifications
You must be signed in to change notification settings - Fork 17
ChannelOptions related tasks #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
80e159d
[#278] Added ChannelOptions with params and modes attributes (TB2c,TB2d)
826eed9
[#278] Moved ChannelOptions to the Ably::Models module. Updated faile…
b8a41b4
Merge remote-tracking branch 'origin/main' into integration/channel-o…
TheSmartnik 7d5e86b
Implement RTL16
TheSmartnik f97bc61
Implement RTS3a
TheSmartnik 603633d
RTL4l
TheSmartnik 3e1f4d5
RTL4m
TheSmartnik c97190b
RSN3a, RSN3c
TheSmartnik d33d9e3
RTL16a
TheSmartnik b766d98
RTS3c1
TheSmartnik ca37d60
RTL4k
TheSmartnik b761004
RTL4k1
TheSmartnik a907de5
After CR improvements
TheSmartnik 81be243
Removed with_different_option_types(...) helper. Added shared_example…
070b48d
Removed support/channel_options_helper require
13c3894
Add extra spec for RTS3c1
TheSmartnik a41b6ed
Add warning on implicit channel set options
TheSmartnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,97 @@ | ||
| module Ably::Models | ||
| # Convert token details argument to a {ChannelOptions} object | ||
| # | ||
| # @param attributes (see #initialize) | ||
| # | ||
| # @return [ChannelOptions] | ||
| def self.ChannelOptions(attributes) | ||
| case attributes | ||
| when ChannelOptions | ||
| return attributes | ||
| else | ||
| ChannelOptions.new(attributes) | ||
| end | ||
| end | ||
|
|
||
| # Represents options of a channel | ||
| class ChannelOptions | ||
| extend Ably::Modules::Enum | ||
| extend Forwardable | ||
| include Ably::Modules::ModelCommon | ||
|
|
||
| MODES = ruby_enum('MODES', | ||
| presence: 0, | ||
| publish: 1, | ||
| subscribe: 2, | ||
| presence_subscribe: 3 | ||
| ) | ||
|
|
||
| attr_reader :attributes | ||
|
|
||
| alias_method :to_h, :attributes | ||
|
|
||
| def_delegators :attributes, :fetch, :size, :empty? | ||
| # Initialize a new ChannelOptions | ||
| # | ||
| # @option params [Hash] (TB2c) params (for realtime client libraries only) a of key/value pairs | ||
| # @option modes [Hash] modes (for realtime client libraries only) an array of ChannelMode | ||
| # @option cipher [Hash,Ably::Models::CipherParams] :cipher A hash of options or a {Ably::Models::CipherParams} to configure the encryption. *:key* is required, all other options are optional. | ||
| # | ||
| def initialize(attrs) | ||
| @attributes = IdiomaticRubyWrapper(attrs.clone) | ||
|
|
||
| attributes[:modes] = modes.to_a.map { |mode| Ably::Models::ChannelOptions::MODES[mode] } if modes | ||
| attributes[:cipher] = Ably::Models::CipherParams(cipher) if cipher | ||
| attributes.clone | ||
| end | ||
|
|
||
| # @!attribute cipher | ||
| # | ||
| # @return [CipherParams] | ||
| def cipher | ||
| attributes[:cipher] | ||
| end | ||
|
|
||
| # @!attribute params | ||
| # | ||
| # @return [Hash] | ||
| def params | ||
| attributes[:params].to_h | ||
| end | ||
|
|
||
| # @!attribute modes | ||
| # | ||
| # @return [Array<ChannelOptions::MODES>] | ||
| def modes | ||
| attributes[:modes] | ||
| end | ||
|
|
||
| # Converts modes to a bitfield that coresponds to ProtocolMessage#flags | ||
| # | ||
| # @return [Integer] | ||
| def modes_to_flags | ||
| modes.map { |mode| Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] }.reduce(:|) | ||
| end | ||
|
|
||
| # @return [Hash] | ||
| # @api private | ||
| def set_params(hash) | ||
| attributes[:params] = hash | ||
| end | ||
|
|
||
| # Sets modes from ProtocolMessage#flags | ||
| # | ||
| # @return [Array<ChannelOptions::MODES>] | ||
| # @api private | ||
| def set_modes_from_flags(flags) | ||
| return unless flags | ||
|
|
||
| message_modes = MODES.select do |mode| | ||
| flag = Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] | ||
| flags & flag == flag | ||
| end | ||
|
|
||
| attributes[:modes] = message_modes.map { |mode| Ably::Models::ChannelOptions::MODES[mode] } | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.