2015-07-21 21:03:47 -04:00
|
|
|
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'
|
2016-05-18 17:12:11 -04:00
|
|
|
# FooChats::BarAppearancesChannel.channel_name # => 'foo_chats:bar_appearances'
|
2015-07-21 21:03:47 -04:00
|
|
|
def channel_name
|
2016-10-28 23:05:58 -04:00
|
|
|
@channel_name ||= name.sub(/Channel$/, "").gsub("::", ":").underscore
|
2015-07-21 21:03:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Delegates to the class' <tt>channel_name</tt>
|
|
|
|
delegate :channel_name, to: :class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|