Parent

Methods

Class/Module Index [+]

Quicksearch

Mongoid::Persistence::Atomic::Bit

This operation is for performing $bit atomic operations against the database.

Public Instance Methods

persist() click to toggle source

Execute the bitwise operation. This correlates to a $bit in MongoDB.

@example Execute the op.

bit.persist

@return [ Integer ] The new value.

@since 2.1.0

# File lib/mongoid/persistence/atomic/bit.rb, line 18
def persist
  prepare do
    current = document[field]
    return nil unless current
    document[field] = value.inject(current) do |result, (bit, val)|
      result = result & val if bit.to_s == "and"
      result = result | val if bit.to_s == "or"
      result
    end
    execute("$bit")
    document[field]
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.