2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-21 21:03:47 -04:00
|
|
|
module ActionCable
|
|
|
|
module Channel
|
|
|
|
module Naming
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2018-04-03 19:58:56 -04:00
|
|
|
module ClassMethods
|
2015-07-21 21:03:47 -04:00
|
|
|
# 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
|
2020-05-24 14:15:38 -04:00
|
|
|
@channel_name ||= name.delete_suffix("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
|