Skip to content

Commit 22ecbe6

Browse files
committed
Revert introduction of forwardable
Mongoid 7.1.0 introduced a regression (see https://jira.mongodb.org/browse/MONGOID-4849) by switching to the builtin ruby forwardable method of delegation rather than relying on the ActiveSupport-provided delegation used before. mongoid-locker was made compatible with the regressed version of mongoid in mongodb/mongoid#4739 Mongoid then fixed this regression in 7.1.1+ with mongodb/mongoid@d078acd, which goes back to the active support way of delegating. The `forwardable` inclusion in mongoid-locker causes incompatibilities when you then include another gem that expects to be able to set up a delegator within a mongoid document class. For example the `mongoid-history` gem expects to be able to delegate using the active-support style here: https://github.com/mongoid/mongoid-history/blob/c8c4de1235c01252dfbdb9fe6c0abfc078ec1443/lib/mongoid/history/trackable.rb#L24-L25 This PR reverts the change to introduce `forwardable`. See mongoid/mongoid-history#238 (comment) for an example of how this interacts poorly with mongoid-history.
1 parent 0795445 commit 22ecbe6

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

lib/mongoid/locker.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'forwardable'
43
require 'securerandom'
54

65
module Mongoid
@@ -104,8 +103,6 @@ def reset!
104103

105104
# @api private
106105
def included(klass)
107-
klass.extend(Forwardable) unless klass.ancestors.include?(Forwardable)
108-
109106
klass.extend ClassMethods
110107
klass.singleton_class.instance_eval { attr_accessor(*MODULE_METHODS) }
111108

@@ -117,7 +114,7 @@ def included(klass)
117114
klass.backoff_algorithm = backoff_algorithm
118115
klass.locking_name_generator = locking_name_generator
119116

120-
klass.def_delegators(klass, *MODULE_METHODS)
117+
klass.delegate(*MODULE_METHODS, to: :class)
121118
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map { |method| [method, "#{method}=".to_sym] } - %i[included reset! configure]), to: self)
122119
end
123120
end

0 commit comments

Comments
 (0)