Skip to content

Commit 82eeb2d

Browse files
committed
MONGOID-5972 Make persist_atomic_operations public
It is called on _root from touchable and creatable, so it was never actually private. Move it above the private keyword (keeping the @api private doc, matching atomic_selector and _root) and drop the send calls at both cross-object call sites.
1 parent 2b0934c commit 82eeb2d

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

‎lib/mongoid/persistable.rb‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ def fail_due_to_callback!(method)
142142
raise Errors::Callback.new(self.class, method)
143143
end
144144

145+
# Persist the atomic operations.
146+
#
147+
# @api private
148+
#
149+
# @example Persist the atomic operations.
150+
# persist_atomic_operations(ops)
151+
#
152+
# @param [ Hash ] operations The atomic operations.
153+
def persist_atomic_operations(operations)
154+
return unless persisted? && operations && !operations.empty?
155+
156+
selector = atomic_selector
157+
_root.collection.find(selector).update_one(positionally(selector, operations), session: _session)
158+
end
159+
145160
private
146161

147162
# Are we executing an atomically block on the current document?
@@ -300,20 +315,5 @@ def persist_or_delay_atomic_operation(operation)
300315
persist_atomic_operations(operation)
301316
end
302317
end
303-
304-
# Persist the atomic operations.
305-
#
306-
# @api private
307-
#
308-
# @example Persist the atomic operations.
309-
# persist_atomic_operations(ops)
310-
#
311-
# @param [ Hash ] operations The atomic operations.
312-
def persist_atomic_operations(operations)
313-
return unless persisted? && operations && !operations.empty?
314-
315-
selector = atomic_selector
316-
_root.collection.find(selector).update_one(positionally(selector, operations), session: _session)
317-
end
318318
end
319319
end

‎lib/mongoid/persistable/creatable.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def insert_as_embedded
135135
positionally(selector, operations),
136136
session: _session
137137
)
138-
_root.send(:persist_atomic_operations, '$set' => deferred_touches) if deferred_touches
138+
_root.persist_atomic_operations('$set' => deferred_touches) if deferred_touches
139139
rescue StandardError
140140
# If the insert failed, the after_save callback will not run to
141141
# consume and clear the merged-touch flag, so clear it here.

‎lib/mongoid/touchable.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def touch(field = nil)
4949

5050
begin
5151
touches = _gather_touch_updates(Time.current, field)
52-
_root.send(:persist_atomic_operations, '$set' => touches) if touches.present?
52+
_root.persist_atomic_operations('$set' => touches) if touches.present?
5353
_run_touch_callbacks_from_root
5454
ensure
5555
_clear_touch_updates(field)

0 commit comments

Comments
 (0)