Class: Mongoid::Persistence::Atomic::Bit
- Includes:
- Operation
- Defined in:
- lib/mongoid/persistence/atomic/bit.rb
Overview
This operation is for performing $bit atomic operations against the database.
Instance Attribute Summary
Attributes included from Operation
#document, #field, #options, #value
Instance Method Summary collapse
-
#persist ⇒ Integer
Execute the bitwise operation.
Methods included from Operation
#collection, #initialize, #operation, #path, #prepare
Instance Method Details
#persist ⇒ Integer
Execute the bitwise operation. This correlates to a $bit in MongoDB.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/persistence/atomic/bit.rb', line 19 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 document[field].tap do collection.update(document.atomic_selector, operation("$bit"), ) document.remove_change(field) end end end |