Sha256: 69dd60eeeb4f2f00a62822230bf458cd64d5c8640d2b73c270e66f43f0356d76

Contents?: true

Size: 662 Bytes

Versions: 13

Compression:

Stored size: 662 Bytes

Contents

# encoding: utf-8
require "mongoid/modifiers/command"
require "mongoid/modifiers/inc"

module Mongoid #:nodoc:
  module Modifiers #:nodoc:
    extend ActiveSupport::Concern

    # Increment the field by the provided value, else if it doesn't exists set
    # it to that value.
    #
    # Options:
    #
    # field: The field to increment.
    # value: The value to increment by.
    # options: Options to pass through to the driver.
    def inc(field, value, options = {})
      current = send(field)
      write_attribute(field, (current ? (current + value) : value))
      Inc.new(self, options).persist(field, value)
      current + value
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mongoid-2.0.0.rc.7 lib/mongoid/modifiers.rb
stonegao-mongoid-2.0.0.rc.6 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.6 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.5 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.4 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.3 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.2 lib/mongoid/modifiers.rb
mongoid-2.0.0.rc.1 lib/mongoid/modifiers.rb
mongoid-2.0.0.beta.20 lib/mongoid/modifiers.rb
mongoid-2.0.0.beta.19 lib/mongoid/modifiers.rb
mongoid-2.0.0.beta.18 lib/mongoid/modifiers.rb
mongoid-2.0.0.beta.17 lib/mongoid/modifiers.rb
mongoid-2.0.0.beta.16 lib/mongoid/modifiers.rb