Skip to content

Commit

Permalink
MONGOID-5664 [Monkey Patch Removal] Remove Object#__setter__ monkey-p…
Browse files Browse the repository at this point in the history
…atch (#5707)

* Remove Object#__setter__ monkey-patch. This is a trivial method so I've just inlined it. (It was already inlined in several other places.)

* deprecate __setter__ instead of removing it

---------

Co-authored-by: Jamis Buck <[email protected]>
  • Loading branch information
johnnyshields and jamis authored Nov 6, 2023
1 parent ccb519c commit 66bd54d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/mongoid/association/relatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_callbacks(callback_type)
#
# @return [ String ] The type setter method.
def type_setter
@type_setter ||= type.__setter__
@type_setter ||= "#{type}=" if type
end

# Whether trying to bind an object using this association should raise
Expand Down Expand Up @@ -233,7 +233,7 @@ def path(document)
#
# @return [ String ] The name of the setter.
def inverse_type_setter
@inverse_type_setter ||= inverse_type.__setter__
@inverse_type_setter ||= "#{inverse_type}=" if inverse_type
end

# Get the name of the method to check if the foreign key has changed.
Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/extensions/nil_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

module Mongoid
module Extensions

# Adds type-casting behavior to NilClass.
module NilClass

# Try to form a setter from this object.
#
# @example Try to form a setter.
# object.__setter__
#
# @return [ nil ] Always nil.
# @deprecated
def __setter__
self
end
Mongoid.deprecate(self, :__setter__)

# Get the name of a nil collection.
#
Expand All @@ -30,4 +30,4 @@ def collectionize
end
end

::NilClass.__send__(:include, Mongoid::Extensions::NilClass)
NilClass.include Mongoid::Extensions::NilClass
2 changes: 2 additions & 0 deletions lib/mongoid/extensions/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def __mongoize_time__
# object.__setter__
#
# @return [ String ] The object as a string plus =.
# @deprecated
def __setter__
"#{self}="
end
Mongoid.deprecate(self, :__setter__)

# Get the value of the object as a mongo friendly sort value.
#
Expand Down

0 comments on commit 66bd54d

Please sign in to comment.