Skip to content

Commit c4efab1

Browse files
committed
improve the name of the extracted method
1 parent b75aaac commit c4efab1

File tree

1 file changed

+24
-5
lines changed
  • lib/mongoid/association/embedded/embeds_many

1 file changed

+24
-5
lines changed

lib/mongoid/association/embedded/embeds_many/proxy.rb

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,38 @@ def id_of(doc)
451451

452452
# Optimized version of #append that handles multiple documents
453453
# in a more efficient way.
454+
#
455+
# @param [ Array<Document> ] documents The documents to append.
456+
#
457+
# @return [ EmbedsMany::Proxy ] This proxy instance.
454458
def append_many(documents, &block)
455-
unique_set = get_unique_new_docs(documents, &block)
459+
unique_set = process_incoming_docs(documents, &block)
456460

457461
_unscoped.concat(unique_set)
458462
_target.push(*scope(unique_set))
459463
update_attributes_hash
460464

461465
unique_set.each { |doc| execute_callback :after_add, doc }
466+
467+
self
462468
end
463469

464-
# Return a list of unique new documents that do not yet exist
465-
# in the association.
466-
def get_unique_new_docs(documents, &block)
470+
# Processes the list of documents, building a list of those
471+
# that are not already in the association, and preparing
472+
# each unique document to be integrated into the association.
473+
#
474+
# The :before_add callback is executed for each unique document
475+
# as part of this step.
476+
#
477+
# @param [ Array<Document> ] documents The incoming documents to
478+
# process.
479+
#
480+
# @yield [ Document ] Optional block to call for each unique
481+
# document.
482+
#
483+
# @return [ Array<Document> ] The list of unique documents that
484+
# do not yet exist in the association.
485+
def process_incoming_docs(documents, &block)
467486
visited_docs = Set.new(_target.map { |doc| id_of(doc) })
468487
next_index = _unscoped.size
469488

@@ -481,7 +500,7 @@ def get_unique_new_docs(documents, &block)
481500
doc._index = next_index
482501
next_index += 1
483502

484-
block&.call(doc)
503+
block&.call(doc) || true
485504
end
486505
end
487506

0 commit comments

Comments
 (0)