Sha256: 2647c28dd0e477d1f60f4e11c5d4865ee529b4dbf0ee4f832fd2b2bd5476e714
Contents?: true
Size: 738 Bytes
Versions: 5
Compression:
Stored size: 738 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: module Atomic #:nodoc: # This class provides atomic $inc behaviour. class Inc < 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 current = document[field] || 0 document[field] = current + value document[field].tap do document.collection.update(document._selector, operation("$inc"), options) document.changes.delete(field.to_s) end end end end end end
Version data entries
5 entries across 5 versions & 2 rubygems