class Mongoid::Persistence::Atomic::Inc
This class provides atomic $inc behaviour.
Public Instance Methods
persist()
click to toggle source
Sends the atomic $inc operation to the database.
@example Persist the new values.
inc.persist
@return [ Object ] The new numeric value.
@since 2.0.0
# File lib/mongoid/persistence/atomic/inc.rb, line 17 def persist prepare do current = document[field] || 0 document[field] = current + value execute("$inc") document[field] end end
Private Instance Methods
cast_value()
click to toggle source
In case we need to cast going to the database.
@api private
@example Cast the value.
operation.cast_value
@return [ Integer, Float ] The value casted.
@since 3.0.3
# File lib/mongoid/persistence/atomic/inc.rb, line 38 def cast_value value.__to_inc__ end