lib/action_cable/channel/naming.rb in actioncable-7.1.5 vs lib/action_cable/channel/naming.rb in actioncable-7.2.0.beta1

- old
+ new

@@ -1,27 +1,28 @@ # frozen_string_literal: true +# :markup: markdown + module ActionCable module Channel module Naming extend ActiveSupport::Concern module ClassMethods - # 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 + # Returns the name of the channel, underscored, without the `Channel` 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' - # FooChats::BarAppearancesChannel.channel_name # => 'foo_chats:bar_appearances' + # ChatChannel.channel_name # => 'chat' + # Chats::AppearancesChannel.channel_name # => 'chats:appearances' + # FooChats::BarAppearancesChannel.channel_name # => 'foo_chats:bar_appearances' def channel_name @channel_name ||= name.delete_suffix("Channel").gsub("::", ":").underscore end end - included do - # Delegates to the class's ::channel_name. - delegate :channel_name, to: :class + def channel_name + self.class.channel_name end end end end