From 5791cc408900f9eb307d3b6e97fcf1520694d427 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Thu, 25 Jul 2024 17:55:41 -0700 Subject: [PATCH] Use `ActiveSupport.on_load` to defer autoloaded Action Cable constants Co-authored-by: Rob Brackett --- lib/lograge/rails_ext/action_cable/channel/base.rb | 5 ++++- .../rails_ext/action_cable/connection/base.rb | 4 +++- lib/lograge/rails_ext/action_cable/server/base.rb | 12 +++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/lograge/rails_ext/action_cable/channel/base.rb b/lib/lograge/rails_ext/action_cable/channel/base.rb index 6ad7ff22..7ed4f4e9 100644 --- a/lib/lograge/rails_ext/action_cable/channel/base.rb +++ b/lib/lograge/rails_ext/action_cable/channel/base.rb @@ -22,4 +22,7 @@ def notification_payload(method_name) end end -ActionCable::Channel::Base.prepend(Lograge::ActionCable::ChannelInstrumentation) + +ActiveSupport.on_load(:action_cable_channel) do + ActionCable::Channel::Base.prepend(Lograge::ActionCable::ChannelInstrumentation) +end diff --git a/lib/lograge/rails_ext/action_cable/connection/base.rb b/lib/lograge/rails_ext/action_cable/connection/base.rb index 9ce285c2..de661341 100644 --- a/lib/lograge/rails_ext/action_cable/connection/base.rb +++ b/lib/lograge/rails_ext/action_cable/connection/base.rb @@ -18,4 +18,6 @@ def notification_payload(method_name) end end -ActionCable::Connection::Base.prepend(Lograge::ActionCable::ConnectionInstrumentation) +ActiveSupport.on_load(:action_cable_connection) do + ActionCable::Connection::Base.prepend(Lograge::ActionCable::ConnectionInstrumentation) +end diff --git a/lib/lograge/rails_ext/action_cable/server/base.rb b/lib/lograge/rails_ext/action_cable/server/base.rb index 3264372a..910bb449 100644 --- a/lib/lograge/rails_ext/action_cable/server/base.rb +++ b/lib/lograge/rails_ext/action_cable/server/base.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true -module ActionCable - module Server - class Base - mattr_accessor :logger - self.logger = Lograge::SilentLogger.new(config.logger) +ActiveSupport.on_load(:action_cable) do + module ActionCable + module Server + class Base + mattr_accessor :logger + self.logger = Lograge::SilentLogger.new(config.logger) + end end end end