diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-01-15 23:49:01 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-01-15 23:49:01 +0530 |
commit | 792fe4b29ce76089672c0741370b10d03a7f076a (patch) | |
tree | 9d65a7313688194a05e88037bf2c7db5ff0ae8e8 /lib | |
parent | 843492ee6c2167115f2bbc9c1b3c82da0ad075f8 (diff) | |
download | rails-792fe4b29ce76089672c0741370b10d03a7f076a.tar.gz rails-792fe4b29ce76089672c0741370b10d03a7f076a.tar.bz2 rails-792fe4b29ce76089672c0741370b10d03a7f076a.zip |
Specify channel name as an attribute
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_cable/channel/base.rb | 2 | ||||
-rw-r--r-- | lib/action_cable/server.rb | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index e091d08c9c..fa284eccbc 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -9,6 +9,8 @@ module ActionCable attr_reader :params + class_attribute :channel_name + class << self def matches?(identifier) raise "Please implement #{name}#matches? method" diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb index 4ee6b15982..1b444a4e7a 100644 --- a/lib/action_cable/server.rb +++ b/lib/action_cable/server.rb @@ -47,8 +47,12 @@ module ActionCable id_key = data['identifier'] id_options = ActiveSupport::JSON.decode(id_key).with_indifferent_access - if subscription = registered_channels.detect { |channel_klass| channel_klass.matches?(id_options) } - @subscriptions[id_key] = subscription.new(self, id_key, id_options) + subscription_klass = registered_channels.detect do |channel_klass| + channel_klass.channel_name == id_options[:channel] && channel_klass.matches?(id_options) + end + + if subscription_klass + @subscriptions[id_key] = subscription_klass.new(self, id_key, id_options) @subscriptions[id_key].subscribe else # No channel found |