Skip to content

Commit 0ce4c5a

Browse files
committed
ActionMailer 7.0 compatibility: ensure deliver callbacks are defined when prepended and patch MessageDelivery on load; avoid Rails <7.1 option
1 parent 1573a16 commit 0ce4c5a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/log_struct/integrations/action_mailer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def self.setup(config)
4141
ActiveSupport.on_load(:action_mailer) { prepend LogStruct::Integrations::ActionMailer::EventLogging }
4242
ActiveSupport.on_load(:action_mailer) { prepend LogStruct::Integrations::ActionMailer::ErrorHandling }
4343
ActiveSupport.on_load(:action_mailer) { prepend LogStruct::Integrations::ActionMailer::Callbacks }
44+
ActiveSupport.on_load(:action_mailer) { LogStruct::Integrations::ActionMailer::Callbacks.patch_message_delivery }
4445

4546
true
4647
end

lib/log_struct/integrations/action_mailer/callbacks.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ module Callbacks
1616
# This will be handled by ActiveSupport::Concern at runtime
1717
included do
1818
include ::ActiveSupport::Callbacks
19-
# Rails < 7.1 does not support skip_after_callbacks_if_terminated option
2019
if defined?(::ActiveSupport) && ::ActiveSupport.gem_version >= Gem::Version.new("7.1.0")
2120
define_callbacks :deliver, skip_after_callbacks_if_terminated: true
2221
else
2322
define_callbacks :deliver
2423
end
2524
end
2625

26+
# When this module is prepended (our integration uses prepend), ensure callbacks are defined
27+
if respond_to?(:prepended)
28+
prepended do
29+
include ::ActiveSupport::Callbacks
30+
if defined?(::ActiveSupport) && ::ActiveSupport.gem_version >= Gem::Version.new("7.1.0")
31+
define_callbacks :deliver, skip_after_callbacks_if_terminated: true
32+
else
33+
define_callbacks :deliver
34+
end
35+
end
36+
end
37+
2738
# Define class methods in a separate module
2839
module ClassMethods
2940
extend T::Sig

0 commit comments

Comments
 (0)