Module: Mongoid::Persistable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Creatable, Deletable, Destroyable, Incrementable, Logical, Poppable, Pullable, Pushable, Renamable, Savable, Settable, Unsettable, Updatable, Upsertable, Positional
- Included in:
- Composable
- Defined in:
- lib/mongoid/persistable.rb,
lib/mongoid/persistable/logical.rb,
lib/mongoid/persistable/savable.rb,
lib/mongoid/persistable/poppable.rb,
lib/mongoid/persistable/pullable.rb,
lib/mongoid/persistable/pushable.rb,
lib/mongoid/persistable/settable.rb,
lib/mongoid/persistable/creatable.rb,
lib/mongoid/persistable/deletable.rb,
lib/mongoid/persistable/renamable.rb,
lib/mongoid/persistable/updatable.rb,
lib/mongoid/persistable/unsettable.rb,
lib/mongoid/persistable/upsertable.rb,
lib/mongoid/persistable/destroyable.rb,
lib/mongoid/persistable/incrementable.rb
Overview
Contains general behaviour for persistence operations.
Defined Under Namespace
Modules: Creatable, Deletable, Destroyable, Incrementable, Logical, Poppable, Pullable, Pushable, Renamable, Savable, Settable, Unsettable, Updatable, Upsertable
Constant Summary collapse
- LIST_OPERATIONS =
The atomic operations that deal with arrays or sets in the db.
[ "$addToSet", "$push", "$pull", "$pullAll" ].freeze
Instance Method Summary collapse
-
#atomically ⇒ true, false
Execute operations atomically (in a single database call) for everything that would happen inside the block.
-
#fail_due_to_callback!(method) ⇒ Object
Raise an error if a callback failed.
-
#fail_due_to_validation! ⇒ Object
Raise an error if validation failed.
- #hasherizer(keys, value) ⇒ Object
Methods included from Unsettable
Methods included from Upsertable
Methods included from Updatable
#update, #update!, #update_attribute
Methods included from Settable
Methods included from Savable
Methods included from Renamable
Methods included from Pushable
Methods included from Pullable
Methods included from Positional
Methods included from Poppable
Methods included from Logical
Methods included from Incrementable
Methods included from Destroyable
Methods included from Deletable
Methods included from Creatable
Instance Method Details
#atomically ⇒ true, false
Execute operations atomically (in a single database call) for everything that would happen inside the block.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mongoid/persistable.rb', line 56 def atomically begin @atomic_updates_to_execute = {} yield(self) if block_given? persist_atomic_operations(@atomic_updates_to_execute) true ensure @atomic_updates_to_execute = nil end end |
#fail_due_to_callback!(method) ⇒ Object
Raise an error if a callback failed.
92 93 94 |
# File 'lib/mongoid/persistable.rb', line 92 def fail_due_to_callback!(method) raise Errors::Callback.new(self.class, method) end |
#fail_due_to_validation! ⇒ Object
Raise an error if validation failed.
77 78 79 |
# File 'lib/mongoid/persistable.rb', line 77 def fail_due_to_validation! raise Errors::Validations.new(self) end |
#hasherizer(keys, value) ⇒ Object
35 36 37 38 |
# File 'lib/mongoid/persistable/settable.rb', line 35 def hasherizer(keys, value) return value if keys.empty? {}.tap { |hash| hash[keys.shift] = hasherizer(keys, value) } end |