Class: Ably::Models::ChannelOptions

Inherits:
Object
  • Object
show all
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 included from Ably::Modules::ModelCommon

#hash

Instance Method Summary collapse

Methods included from Ably::Modules::ModelCommon

#==, #[], #as_json, included, #to_json, #to_s

Methods included from Ably::Modules::MessagePack

#to_msgpack

Constructor Details

#initialize(attrs) ⇒ ChannelOptions

Initialize a new ChannelOptions

Parameters:

  • params (Hash)

    a customizable set of options

  • modes (Hash)

    a customizable set of options

  • cipher (Hash)

    a customizable set of options



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

#attributesObject (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

#cipherCipherParams

Returns:



51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 51

def cipher
  attributes[:cipher]
end

#modesArray<ChannelOptions::MODES>

Returns:



65
66
67
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 65

def modes
  attributes[:modes]
end

#paramsHash

Returns:

  • (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_flagsInteger

Converts modes to a bitfield that coresponds to ProtocolMessage#flags

Returns:

  • (Integer)


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

Returns:



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

  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

#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.

Returns:

  • (Hash)


78
79
80
# File 'lib/submodules/ably-ruby/lib/ably/models/channel_options.rb', line 78

def set_params(hash)
  attributes[:params] = hash
end