Module: Mongoid::Persistence::Atomic
- Defined in:
- lib/mongoid/persistence/atomic.rb,
lib/mongoid/persistence/atomic/bit.rb,
lib/mongoid/persistence/atomic/inc.rb,
lib/mongoid/persistence/atomic/pop.rb,
lib/mongoid/persistence/atomic/pull.rb,
lib/mongoid/persistence/atomic/push.rb,
lib/mongoid/persistence/atomic/sets.rb,
lib/mongoid/persistence/atomic/unset.rb,
lib/mongoid/persistence/atomic/rename.rb,
lib/mongoid/persistence/atomic/pull_all.rb,
lib/mongoid/persistence/atomic/push_all.rb,
lib/mongoid/persistence/atomic/operation.rb,
lib/mongoid/persistence/atomic/add_to_set.rb
Overview
This module provides the explicit atomic operations helpers on the document itself.
Defined Under Namespace
Modules: Operation Classes: AddToSet, Bit, Inc, Pop, Pull, PullAll, Push, PushAll, Rename, Sets, Unset
Instance Method Summary collapse
-
#add_to_set(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $addToSet of the provided value on the supplied field.
-
#bit(field, value, options = {}) ⇒ Integer
Performs an atomic $bit operation on the field with the provided hash of bitwise ops to execute in order.
-
#inc(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $inc of the provided value on the supplied field.
-
#pop(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pop of the provided value on the supplied field.
-
#pull(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pull of the provided value on the supplied field.
-
#pull_all(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pullAll of the provided value on the supplied field.
-
#push(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $push of the provided value on the supplied field.
-
#push_all(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pushAll of the provided value on the supplied field.
-
#rename(field, value, options = {}) ⇒ Object
Performs the atomic $rename from the old field to the new field name.
-
#set(field, value = nil, options = {}) ⇒ Array<Object>
Performs an atomic $set of the provided value on the supplied field.
-
#unset(*args) ⇒ nil
Performs the atomic $unset on the supplied field.
Instance Method Details
#add_to_set(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $addToSet of the provided value on the supplied field. If the field does not exist it will be initialized as an empty array.
If the value already exists on the array it will not be added.
40 41 42 |
# File 'lib/mongoid/persistence/atomic.rb', line 40 def add_to_set(field, value, = {}) AddToSet.new(self, field, value, ).persist end |
#bit(field, value, options = {}) ⇒ Integer
Performs an atomic $bit operation on the field with the provided hash of bitwise ops to execute in order.
63 64 65 |
# File 'lib/mongoid/persistence/atomic.rb', line 63 def bit(field, value, = {}) Bit.new(self, field, value, ).persist end |
#inc(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $inc of the provided value on the supplied field. If the field does not exist it will be initialized as the provided value.
81 82 83 |
# File 'lib/mongoid/persistence/atomic.rb', line 81 def inc(field, value, = {}) Inc.new(self, field, value, ).persist end |
#pop(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pop of the provided value on the supplied field.
101 102 103 |
# File 'lib/mongoid/persistence/atomic.rb', line 101 def pop(field, value, = {}) Pop.new(self, field, value, ).persist end |
#pull(field, value, options = {}) ⇒ Array<Object>
Support for a $pull with an expression is not yet supported.
Performs an atomic $pull of the provided value on the supplied field.
120 121 122 |
# File 'lib/mongoid/persistence/atomic.rb', line 120 def pull(field, value, = {}) Pull.new(self, field, value, ).persist end |
#pull_all(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pullAll of the provided value on the supplied field. If the field does not exist it will be initialized as an empty array.
138 139 140 |
# File 'lib/mongoid/persistence/atomic.rb', line 138 def pull_all(field, value, = {}) PullAll.new(self, field, value, ).persist end |
#push(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $push of the provided value on the supplied field. If the field does not exist it will be initialized as an empty array.
155 156 157 |
# File 'lib/mongoid/persistence/atomic.rb', line 155 def push(field, value, = {}) Push.new(self, field, value, ).persist end |
#push_all(field, value, options = {}) ⇒ Array<Object>
Performs an atomic $pushAll of the provided value on the supplied field. If the field does not exist it will be initialized as an empty array.
172 173 174 |
# File 'lib/mongoid/persistence/atomic.rb', line 172 def push_all(field, value, = {}) PushAll.new(self, field, value, ).persist end |
#rename(field, value, options = {}) ⇒ Object
Performs the atomic $rename from the old field to the new field name.
188 189 190 |
# File 'lib/mongoid/persistence/atomic.rb', line 188 def rename(field, value, = {}) Rename.new(self, field, value, ).persist end |
#set(field, value = nil, options = {}) ⇒ Array<Object>
Performs an atomic $set of the provided value on the supplied field. If the field does not exist it will be initialized as the provided value.
206 207 208 |
# File 'lib/mongoid/persistence/atomic.rb', line 206 def set(field, value = nil, = {}) Sets.new(self, field, value, ).persist end |