lib/submodules/ably-ruby/lib/ably/modules/channels_collection.rb in ably-rest-1.1.8 vs lib/submodules/ably-ruby/lib/ably/modules/channels_collection.rb in ably-rest-1.2.0

- old
+ new

@@ -11,18 +11,25 @@ end # Return a Channel for the given name # # @param name [String] The name of the channel - # @param channel_options [Hash] Channel options including the encryption options + # @param channel_options [Hash, Ably::Models::ChannelOptions] A hash of options or a {Ably::Models::ChannelOptions} # # @return [Channel] # def get(name, channel_options = {}) if channels.has_key?(name) channels[name].tap do |channel| - channel.update_options channel_options if channel_options && !channel_options.empty? + if channel_options && !channel_options.empty? + if channel.respond_to?(:need_reattach?) && channel.need_reattach? + raise_implicit_options_update + else + warn_implicit_options_update + channel.options = channel_options + end + end end else channels[name] ||= channel_klass.new(client, name, channel_options) end end @@ -68,9 +75,22 @@ return to_enum(:each) unless block_given? channels.values.each(&block) end private + + def raise_implicit_options_update + raise ArgumentError, "You are trying to indirectly update channel options which will trigger reattachment of the channel. Please use Channel#set_options directly if you wish to continue" + end + + def warn_implicit_options_update + logger.warn { "Channels#get: Using this method to update channel options is deprecated and may be removed in a future version of ably-ruby. Please use Channel#setOptions instead" } + end + + def logger + client.logger + end + def client @client end def channel_klass