aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/channel/base.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-11-04 17:22:48 -0600
committerPratik Naik <pratiknaik@gmail.com>2015-11-04 17:22:48 -0600
commitcb4ef80f20a23e9c42876b039d8af7d02fd416fb (patch)
tree5e8c2eaf367a9ee395f1213624ad42a08cbf4f06 /lib/action_cable/channel/base.rb
parentee06b33e19019e771f0305a40b15885c22499a8b (diff)
parent7c1631fa48b8862f37d1026b4f0cf1061dd6947a (diff)
downloadrails-cb4ef80f20a23e9c42876b039d8af7d02fd416fb.tar.gz
rails-cb4ef80f20a23e9c42876b039d8af7d02fd416fb.tar.bz2
rails-cb4ef80f20a23e9c42876b039d8af7d02fd416fb.zip
Merge branch 'master' into subscription-rejection
Diffstat (limited to 'lib/action_cable/channel/base.rb')
-rw-r--r--lib/action_cable/channel/base.rb23
1 files changed, 7 insertions, 16 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb
index 31b8dece4a..67b312e5ea 100644
--- a/lib/action_cable/channel/base.rb
+++ b/lib/action_cable/channel/base.rb
@@ -76,10 +76,7 @@ module ActionCable
SUBSCRIPTION_CONFIRMATION_INTERNAL_MESSAGE = 'confirm_subscription'.freeze
SUBSCRIPTION_REJECTION_INTERNAL_MESSAGE = 'reject_subscription'.freeze
- on_subscribe :subscribed
- on_unsubscribe :unsubscribed
-
- attr_reader :params, :connection, :identifier
+ attr_reader :params, :connection, ::identifier
delegate :logger, to: :connection
class << self
@@ -147,7 +144,9 @@ module ActionCable
# Called by the cable connection when its cut so the channel has a chance to cleanup with callbacks.
# This method is not intended to be called directly by the user. Instead, overwrite the #unsubscribed callback.
def unsubscribe_from_channel
- run_unsubscribe_callbacks
+ run_callbacks :unsubscribe do
+ unsubscribed
+ end
end
@@ -202,7 +201,9 @@ module ActionCable
def subscribe_to_channel
- run_subscribe_callbacks
+ run_callbacks :subscribe do
+ subscribed
+ end
if subscription_rejected?
reject_subscription
@@ -238,19 +239,10 @@ module ActionCable
end
end
- def run_subscribe_callbacks
- self.class.on_subscribe_callbacks.each { |callback| send(callback) }
- end
-
- def run_unsubscribe_callbacks
- self.class.on_unsubscribe_callbacks.each { |callback| send(callback) }
- end
-
def transmit_subscription_confirmation
unless subscription_confirmation_sent?
logger.info "#{self.class.name} is transmitting the subscription confirmation"
connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: SUBSCRIPTION_CONFIRMATION_INTERNAL_MESSAGE)
-
@subscription_confirmation_sent = true
end
end
@@ -264,7 +256,6 @@ module ActionCable
logger.info "#{self.class.name} is transmitting the subscription rejection"
connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: SUBSCRIPTION_REJECTION_INTERNAL_MESSAGE)
end
-
end
end
end