Class: Ably::Realtime::Channels
- Inherits:
-
Object
- Object
- Ably::Realtime::Channels
- Includes:
- Modules::ChannelsCollection
- Defined in:
- lib/ably/realtime/channels.rb
Overview
Class that maintains a map of Channels ensuring Channels are reused
Instance Attribute Summary
Attributes included from Modules::ChannelsCollection
Instance Method Summary collapse
-
#fetch(*args) {|options| ... } ⇒ Ably::Realtime::Channel
Return a Channel for the given name if it exists, else the block will be called.
-
#get(*args) ⇒ Ably::Realtime::Channel
Return a Channel for the given name.
-
#get_channel_serials ⇒ Hash
private
Serials - map of channel name to respective channel serial.
- #initialize(client) ⇒ Ably::Realtime::Channels constructor
-
#release(channel) ⇒ void
Detaches the Realtime Channel and releases all associated resources.
-
#set_channel_serials(serials) ⇒ Object
private
Sets channel serial to each channel from given serials hashmap.
Methods included from Modules::ChannelsCollection
Constructor Details
#initialize(client) ⇒ Ably::Realtime::Channels
9 10 11 |
# File 'lib/ably/realtime/channels.rb', line 9 def initialize(client) super client, Ably::Realtime::Channel end |
Instance Method Details
#fetch(*args) {|options| ... } ⇒ Ably::Realtime::Channel
Return a Ably::Realtime::Channel for the given name if it exists, else the block will be called. This method is intentionally similar to Hash#fetch providing a simple way to check if a channel exists or not without creating one
33 34 35 |
# File 'lib/ably/realtime/channels.rb', line 33 def fetch(*args) super end |
#get(*args) ⇒ Ably::Realtime::Channel
Return a Ably::Realtime::Channel for the given name
20 21 22 |
# File 'lib/ably/realtime/channels.rb', line 20 def get(*args) super end |
#get_channel_serials ⇒ 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 serials - map of channel name to respective channel serial.
61 62 63 64 65 66 67 |
# File 'lib/ably/realtime/channels.rb', line 61 def get_channel_serials channel_serials = {} self.each do |channel| channel_serials[channel.name] = channel.properties.channel_serial if channel.state == :attached end channel_serials end |
#release(channel) ⇒ void
This method returns an undefined value.
Detaches the Realtime Channel and releases all associated resources.
Releasing a Realtime Channel is not typically necessary as a channel, once detached, consumes no resources other than the memory footprint of the Realtime Channel object. Release channels to free up resources if required
44 45 46 47 48 |
# File 'lib/ably/realtime/channels.rb', line 44 def release(channel) get(channel).detach do @channels.delete(channel) end if @channels.has_key?(channel) end |
#set_channel_serials(serials) ⇒ Object
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 channel serial to each channel from given serials hashmap
53 54 55 56 57 |
# File 'lib/ably/realtime/channels.rb', line 53 def set_channel_serials(serials) serials.each do |channel_name, channel_serial| get(channel_name).properties.channel_serial = channel_serial end end |