Skip to content

Commit

Permalink
MONGOID-5560 Updates per rubocop (mongodb#5634)
Browse files Browse the repository at this point in the history
* MONGOID-5560 alias EmbedsMany#delete_one to EmbedsMany#delete

* MONGOID-5560 alias HasMany::Proxy#delete_one to HasMany::Proxy#delete

* MONGOID-5560 alias HasAndBelongsToMany::Proxy#delete_one to HasAndBelongsToMany::Proxy#delete

* rubocop appeasement

* turns out, EmbedsMany::Proxy#delete_one *was* being used.

Let's pull that out of private visibility, make it @api private, and give it
a better name, besides. Should make it clearer that this has internal use
outside of this class.

* linter suggestions

* preserve double underscore for certain backing variables

this prevents conflicts with associations, which create backing variables prefixed with a single underscore

* fix starts_with? -> start_with?
  • Loading branch information
jamis authored Jun 12, 2023
1 parent 00c86f9 commit 3bfbd3d
Show file tree
Hide file tree
Showing 11 changed files with 647 additions and 558 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Layout/SpaceInsideArrayLiteralBrackets:
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false

Metrics/ClassLength:
Max: 200

Metrics/ModuleLength:
Enabled: false

Expand Down
12 changes: 4 additions & 8 deletions lib/mongoid/association/embedded/embedded_in/proxy.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true
# rubocop:todo all

module Mongoid
module Association
module Embedded
class EmbeddedIn

# Proxy class for representing :embedded_in associations.
class Proxy < Association::One

# Instantiate a new embedded_in association.
#
# @example Create the new association.
Expand All @@ -19,7 +17,7 @@ class Proxy < Association::One
#
# @return [ In ] The proxy.
def initialize(base, target, association)
init(base, target, association) do
super do
characterize_one(_target)
bind_one
end
Expand Down Expand Up @@ -66,9 +64,7 @@ def binding
#
# @param [ Document ] document The document to set the association metadata on.
def characterize_one(document)
unless _base._association
_base._association = _association.inverse_association(document)
end
_base._association ||= _association.inverse_association(document)
end

# Are we able to persist this association?
Expand All @@ -89,7 +85,7 @@ class << self
# @param [ Array<Mongoid::Document> ] docs The parent documents
# that possess the given associations, which ought to be
# populated by the eager-loaded documents.
#
#
# @return [ Mongoid::Association::Embedded::Eager ]
def eager_loader(associations, docs)
Eager.new(associations, docs)
Expand Down
Loading

0 comments on commit 3bfbd3d

Please sign in to comment.