Sha256: 2e59e704ce722f6c2d66ea3a2e0c3d19d65dd40c4f44c9d766e3177a4b792841
Contents?: true
Size: 790 Bytes
Versions: 188
Compression:
Stored size: 790 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: module Atomic #:nodoc: # This class provides atomic $inc behaviour. class Inc include Operation # Sends the atomic $inc operation to the database. # # @example Persist the new values. # inc.persist # # @return [ Object ] The new integer value. # # @since 2.0.0 def persist prepare do current = document[field] || 0 document[field] = current + value document[field].tap do collection.update(document.atomic_selector, operation("$inc"), options) document.remove_change(field) end end end end end end end
Version data entries
188 entries across 96 versions & 4 rubygems