Sha256: 59a511b2874802363aed56a13aad7a43048c8ec4d07ace6d7b287102ebc9a1ec
Contents?: true
Size: 923 Bytes
Versions: 188
Compression:
Stored size: 923 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: module Atomic #:nodoc: # This class provides the ability to perform an explicit $pop # modification on a specific field. class Pop include Operation # Sends the atomic $pop operation to the database. # # @example Persist the new values. # pop.persist # # @return [ Object ] The new array value. # # @since 2.1.0 def persist prepare do if document[field] values = document.send(field) value > 0 ? values.pop : values.shift values.tap do collection.update(document.atomic_selector, operation("$pop"), options) document.remove_change(field) if document.persisted? end end end end end end end end
Version data entries
188 entries across 96 versions & 4 rubygems