From bd6278552fb4ad776ac0cf72e0d601b68401cb12 Mon Sep 17 00:00:00 2001 From: adamsosterics Date: Mon, 9 Feb 2026 14:23:33 +0100 Subject: [PATCH] Allow application to be eager loaded without ActionCable When Zeitwerk loads these files it expects classes defined in them even if ActionCable is not used. --- .../activity_notification/notification_api_channel.rb | 10 +++++----- .../notification_api_with_devise_channel.rb | 6 +++--- .../activity_notification/notification_channel.rb | 2 ++ .../notification_with_devise_channel.rb | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/channels/activity_notification/notification_api_channel.rb b/app/channels/activity_notification/notification_api_channel.rb index ce2eca61..8d209e78 100644 --- a/app/channels/activity_notification/notification_api_channel.rb +++ b/app/channels/activity_notification/notification_api_channel.rb @@ -1,8 +1,8 @@ -if defined?(ActionCable) - # Action Cable API channel to subscribe broadcasted notifications. - class ActivityNotification::NotificationApiChannel < ActivityNotification::NotificationChannel - # ActionCable::Channel::Base#subscribed - # @see https://api.rubyonrails.org/classes/ActionCable/Channel/Base.html#method-i-subscribed +# Action Cable API channel to subscribe broadcasted notifications. +class ActivityNotification::NotificationApiChannel < ActivityNotification::NotificationChannel + if defined?(ActionCable) + # ActionCable::Channel::Base#subscribed + # @see https://api.rubyonrails.org/classes/ActionCable/Channel/Base.html#method-i-subscribed def subscribed stream_from "#{ActivityNotification.config.notification_api_channel_prefix}_#{@target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{@target.id}" rescue diff --git a/app/channels/activity_notification/notification_api_with_devise_channel.rb b/app/channels/activity_notification/notification_api_with_devise_channel.rb index 759c8a44..1a4fde17 100644 --- a/app/channels/activity_notification/notification_api_with_devise_channel.rb +++ b/app/channels/activity_notification/notification_api_with_devise_channel.rb @@ -1,6 +1,6 @@ -if defined?(ActionCable) - # Action Cable API channel to subscribe broadcasted notifications with Devise authentication. - class ActivityNotification::NotificationApiWithDeviseChannel < ActivityNotification::NotificationApiChannel +# Action Cable API channel to subscribe broadcasted notifications with Devise authentication. +class ActivityNotification::NotificationApiWithDeviseChannel < ActivityNotification::NotificationApiChannel + if defined?(ActionCable) # Include PolymorphicHelpers to resolve string extentions include ActivityNotification::PolymorphicHelpers diff --git a/app/channels/activity_notification/notification_channel.rb b/app/channels/activity_notification/notification_channel.rb index 40f5d2ea..c26a3190 100644 --- a/app/channels/activity_notification/notification_channel.rb +++ b/app/channels/activity_notification/notification_channel.rb @@ -34,4 +34,6 @@ def authenticate_target! reject if @target.nil? || @target.notification_action_cable_with_devise? end end +else + class ActivityNotification::NotificationChannel; end end diff --git a/app/channels/activity_notification/notification_with_devise_channel.rb b/app/channels/activity_notification/notification_with_devise_channel.rb index 2c4b8d3e..c8967c01 100644 --- a/app/channels/activity_notification/notification_with_devise_channel.rb +++ b/app/channels/activity_notification/notification_with_devise_channel.rb @@ -1,6 +1,6 @@ -if defined?(ActionCable) - # Action Cable channel to subscribe broadcasted notifications with Devise authentication. - class ActivityNotification::NotificationWithDeviseChannel < ActivityNotification::NotificationChannel +# Action Cable channel to subscribe broadcasted notifications with Devise authentication. +class ActivityNotification::NotificationWithDeviseChannel < ActivityNotification::NotificationChannel + if defined?(ActionCable) # Include PolymorphicHelpers to resolve string extentions include ActivityNotification::PolymorphicHelpers