Sha256: 039db6666aff647a0d1df76d07c210eea6cdc92dd629c34b0f3bd6efa87b0415

Contents?: true

Size: 1.91 KB

Versions: 67

Compression:

Stored size: 1.91 KB

Contents

module Ably
  module Realtime
    # Class that maintains a map of Channels ensuring Channels are reused
    class Channels
      include Ably::Modules::ChannelsCollection

      # @return [Ably::Realtime::Channels]
      def initialize(client)
        super client, Ably::Realtime::Channel
      end

      # @!method get(name, channel_options = {})
      # Return a {Ably::Realtime::Channel} for the given name
      #
      # @param name [String] The name of the channel
      # @param channel_options [Hash] Channel options, currently reserved for Encryption options
      # @return [Ably::Realtime::Channel}
      #
      def get(*args)
        super
      end

      # @!method fetch(name, &missing_block)
      # Return a {Ably::Realtime::Channel} for the given name if it exists, else the block will be called.
      # This method is intentionally similar to {http://ruby-doc.org/core-2.1.3/Hash.html#method-i-fetch Hash#fetch} providing a simple way to check if a channel exists or not without creating one
      #
      # @param name [String] The name of the channel
      # @yield [options] (optional) if a missing_block is passed to this method and no channel exists matching the name, this block is called
      # @yieldparam [String] name of the missing channel
      # @return [Ably::Realtime::Channel]
      #
      def fetch(*args)
        super
      end

      # Detaches the {Ably::Realtime::Channel 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 {Ably::Realtime::Channel Realtime Channel object}. Release channels to free up resources if required
      #
      # @return [void]
      #
      def release(channel)
        get(channel).detach do
          @channels.delete(channel)
        end if @channels.has_key?(channel)
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 2 rubygems

Version Path
ably-0.7.6 lib/ably/realtime/channels.rb
ably-rest-0.7.5 lib/submodules/ably-ruby/lib/ably/realtime/channels.rb
ably-0.7.5 lib/ably/realtime/channels.rb
ably-0.7.4 lib/ably/realtime/channels.rb
ably-rest-0.7.3 lib/submodules/ably-ruby/lib/ably/realtime/channels.rb
ably-0.7.2 lib/ably/realtime/channels.rb
ably-0.7.1 lib/ably/realtime/channels.rb