Class: Ably::Models::ChannelOptions
- Inherits:
-
Object
- Object
- Ably::Models::ChannelOptions
- Extended by:
- Ably::Modules::Enum, Forwardable
- Includes:
- Ably::Modules::ModelCommon
- Defined in:
- lib/submodules/ably-ruby/lib/ably/models/channel_options.rb
Overview
Represents options of a channel
Constant Summary collapse
- MODES =
Describes the possible flags used to configure client capabilities, using MODES.
PRESENCE The client can enter the presence set. PUBLISH The client can publish . SUBSCRIBE The client can subscribe to . PRESENCE_SUBSCRIBE The client can receive presence . ruby_enum('MODES', presence: 0, publish: 1, subscribe: 2, presence_subscribe: 3 )
Instance Attribute Summary collapse
-
#attributes ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute attributes.
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#cipher ⇒ CipherParams
Requests encryption for this channel when not null, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key).
-
#initialize(attrs) ⇒ ChannelOptions
constructor
Initialize a new ChannelOptions.
-
#modes ⇒ Array<ChannelOptions::MODES>
An array of Ably:Models:ChannelOptions::MODES objects.
-
#modes_to_flags ⇒ Integer
Converts modes to a bitfield that coresponds to ProtocolMessage#flags.
-
#params ⇒ Hash
Channel Parameters that configure the behavior of the channel.
-
#set_modes_from_flags(flags) ⇒ Array<ChannelOptions::MODES>
private
Sets modes from ProtocolMessage#flags.
- #set_params(hash) ⇒ Hash private
Methods included from Ably::Modules::ModelCommon
#==, #[], #as_json, included, #to_json, #to_s
Methods included from Ably::Modules::MessagePack
Constructor Details
#initialize(attrs) ⇒ ChannelOptions
Initialize a new ChannelOptions
52 53 54 55 56 57 58 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 52 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute attributes.
39 40 41 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 39 def attributes @attributes end |
Instance Method Details
#cipher ⇒ CipherParams
Requests encryption for this channel when not null, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key). See an example.
67 68 69 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 67 def cipher attributes[:cipher] end |
#modes ⇒ Array<ChannelOptions::MODES>
An array of Ably:Models:ChannelOptions::MODES objects.
87 88 89 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 87 def modes attributes[:modes] end |
#modes_to_flags ⇒ Integer
Converts modes to a bitfield that coresponds to ProtocolMessage#flags
95 96 97 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 95 def modes_to_flags modes.map { |mode| Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] }.reduce(:|) end |
#params ⇒ Hash
Channel Parameters that configure the behavior of the channel.
77 78 79 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 77 def params attributes[:params].to_h end |
#set_modes_from_flags(flags) ⇒ Array<ChannelOptions::MODES>
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.
Sets modes from ProtocolMessage#flags
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 109 def set_modes_from_flags(flags) return unless flags = MODES.select do |mode| flag = Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] flags & flag == flag end attributes[:modes] = .map { |mode| Ably::Models::ChannelOptions::MODES[mode] } end |
#set_params(hash) ⇒ Hash
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.
101 102 103 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 101 def set_params(hash) attributes[:params] = hash end |