diff options
author | Lachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au> | 2015-07-22 11:03:47 +1000 |
---|---|---|
committer | Lachlan Sylvester <lachlan.sylvester@publicisfrontfoot.com.au> | 2015-07-28 17:31:37 +1000 |
commit | 5954fd1e0aa907e07ffff932aedc51109d4ce56d (patch) | |
tree | 76fc4b396065d92d6b62b0f3ce74b122d97901b1 /lib/action_cable/channel/naming.rb | |
parent | 6ee8bb9310f78de85e6b89c8cac33493b0582383 (diff) | |
download | rails-5954fd1e0aa907e07ffff932aedc51109d4ce56d.tar.gz rails-5954fd1e0aa907e07ffff932aedc51109d4ce56d.tar.bz2 rails-5954fd1e0aa907e07ffff932aedc51109d4ce56d.zip |
add broadcast_to and stream_for methods as per #26
Diffstat (limited to 'lib/action_cable/channel/naming.rb')
-rw-r--r-- | lib/action_cable/channel/naming.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/action_cable/channel/naming.rb b/lib/action_cable/channel/naming.rb new file mode 100644 index 0000000000..4c9d53b15a --- /dev/null +++ b/lib/action_cable/channel/naming.rb @@ -0,0 +1,22 @@ +module ActionCable + module Channel + module Naming + extend ActiveSupport::Concern + + class_methods do + # Returns the name of the channel, underscored, without the <tt>Channel</tt> ending. + # If the channel is in a namespace, then the namespaces are represented by single + # colon separators in the channel name. + # + # ChatChannel.channel_name # => 'chat' + # Chats::AppearancesChannel.channel_name # => 'chats:appearances' + def channel_name + @channel_name ||= name.sub(/Channel$/, '').gsub('::',':').underscore + end + end + + # Delegates to the class' <tt>channel_name</tt> + delegate :channel_name, to: :class + end + end +end |