Skip to content

Commit

Permalink
Fix compat with Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed May 27, 2024
1 parent 746fe19 commit 4c4593e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/mongoid/interceptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def run_targeted_callbacks(place, kind)
end
self.class.send :define_method, name do
env = ActiveSupport::Callbacks::Filters::Environment.new(self, false, nil)
sequence = chain.compile
sequence = compile_callbacks(chain)
sequence.invoke_before(env)
env.value = !env.halted
sequence.invoke_after(env)
Expand All @@ -248,5 +248,24 @@ def run_targeted_callbacks(place, kind)
end
send(name)
end

# Compile the callback chain.
#
# This method hides the differences between ActiveSupport implementations
# before and after 7.1.
#
# @param [ ActiveSupport::Callbacks::CallbackChain ] chain The callback chain.
# @param [ Symbol | nil ] type The type of callback chain to compile.
#
# @return [ ActiveSupport::Callbacks::CallbackSequence ] The compiled callback sequence.
def compile_callbacks(chain, type = nil)
if chain.method(:compile).arity == 0
# ActiveSupport < 7.1
chain.compile
else
# ActiveSupport >= 7.1
chain.compile(type)
end
end
end
end

0 comments on commit 4c4593e

Please sign in to comment.