Class: Ably::Models::ChannelOptions

Inherits:
Object
  • Object
show all
Extended by:
Ably::Modules::Enum, Forwardable
Includes:
Ably::Modules::ModelCommon
Defined in:
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 messages.
SUBSCRIBE		          The client can subscribe to messages.
PRESENCE_SUBSCRIBE		The client can receive presence messages.
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



52
53
54
55
56
57
58
# File '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

#attributesObject (readonly) Also known as: to_h

Returns the value of attribute attributes.



39
40
41
# File 'lib/ably/models/channel_options.rb', line 39

def attributes
  @attributes
end

Instance Method Details

#cipherCipherParams

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.

Returns:



67
68
69
# File 'lib/ably/models/channel_options.rb', line 67

def cipher
  attributes[:cipher]
end

#modesArray<ChannelOptions::MODES>

An array of Ably:Models:ChannelOptions::MODES objects.

Returns:



87
88
89
# File 'lib/ably/models/channel_options.rb', line 87

def modes
  attributes[:modes]
end

#modes_to_flagsInteger

Converts modes to a bitfield that coresponds to ProtocolMessage#flags

Returns:

  • (Integer)


95
96
97
# File '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

#paramsHash

Channel Parameters that configure the behavior of the channel.

Returns:

  • (Hash)


77
78
79
# File '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

Returns:



109
110
111
112
113
114
115
116
117
118
# File 'lib/ably/models/channel_options.rb', line 109

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)


101
102
103
# File 'lib/ably/models/channel_options.rb', line 101

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