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 =
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.
- #cipher ⇒ CipherParams
- #modes ⇒ Array<ChannelOptions::MODES>
- #params ⇒ Hash
Attributes included from Ably::Modules::ModelCommon
Instance Method Summary collapse
-
#initialize(attrs) ⇒ ChannelOptions
constructor
Initialize a new ChannelOptions.
-
#modes_to_flags ⇒ Integer
Converts modes to a bitfield that coresponds to ProtocolMessage#flags.
-
#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
40 41 42 43 44 45 46 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 40 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.
29 30 31 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 29 def attributes @attributes end |
#cipher ⇒ CipherParams
51 52 53 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 51 def cipher attributes[:cipher] end |
#modes ⇒ Array<ChannelOptions::MODES>
65 66 67 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 65 def modes attributes[:modes] end |
#params ⇒ Hash
58 59 60 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 58 def params attributes[:params].to_h end |
Instance Method Details
#modes_to_flags ⇒ Integer
Converts modes to a bitfield that coresponds to ProtocolMessage#flags
72 73 74 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 72 def modes_to_flags modes.map { |mode| Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] }.reduce(:|) 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
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 86 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.
78 79 80 |
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 78 def set_params(hash) attributes[:params] = hash end |