From 8bd5a80ec5b6c11b3d477fa3af36cbe6e860bb4b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 18 Jun 2015 17:01:04 +0200 Subject: Allow unsubscribing from all current redis channels --- lib/action_cable/channel/redis.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'lib/action_cable') diff --git a/lib/action_cable/channel/redis.rb b/lib/action_cable/channel/redis.rb index 6fc6ac179f..6d114eee7e 100644 --- a/lib/action_cable/channel/redis.rb +++ b/lib/action_cable/channel/redis.rb @@ -1,11 +1,10 @@ module ActionCable module Channel - module Redis extend ActiveSupport::Concern included do - on_unsubscribe :unsubscribe_from_redis_channels + on_unsubscribe :unsubscribe_from_all_channels delegate :pubsub, to: :connection end @@ -18,24 +17,22 @@ module ActionCable pubsub.subscribe(redis_channel, &callback) end - protected - def unsubscribe_from_redis_channels - if @_redis_channels - @_redis_channels.each do |channel, callback| - logger.info "Unsubscribing from the redis channel: #{channel}" - pubsub.unsubscribe_proc(channel, callback) - end + def unsubscribe_from_all_channels + if @_redis_channels + @_redis_channels.each do |channel, callback| + logger.info "Unsubscribing from the redis channel: #{channel}" + pubsub.unsubscribe_proc(channel, callback) end end + end + protected def default_subscription_callback(channel) -> (message) do logger.info "Received a message over the redis channel: #{channel}" broadcast ActiveSupport::JSON.decode(message) end end - end - end -end \ No newline at end of file +end -- cgit v1.2.3