Module: Mongoid::Safety
Overview
The Safety
module is used to provide a DSL to execute database operations in safe mode on a per query basis, either from the Document
class level or instance level.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.merge_safety_options(options = {}) ⇒ Hash
Static class method of easily getting the desired safe mode options from anywhere in the framework.
Instance Method Summary collapse
-
#safely(safety = true) ⇒ Proxy
Execute the following instance-level persistence operation in safe mode.
-
#unsafely ⇒ Proxy
Execute the following instance-level persistence operation without safe mode.
Class Method Details
.merge_safety_options(options = {}) ⇒ Hash
Static class method of easily getting the desired safe mode options from anywhere in the framework.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mongoid/safety.rb', line 55 def ( = {}) ||= {} return if [:safe] unless Threaded..nil? safety = Threaded. else safety = Mongoid.persist_in_safe_mode end .merge!({ :safe => safety }) end |
Instance Method Details
#safely(safety = true) ⇒ Proxy
Execute the following instance-level persistence operation in safe mode.
26 27 28 |
# File 'lib/mongoid/safety.rb', line 26 def safely(safety = true) tap { Threaded. = safety } end |
#unsafely ⇒ Proxy
Execute the following instance-level persistence operation without safe mode. Allows per-request overriding of safe mode when the persist_in_safe_mode config option is turned on.
38 39 40 |
# File 'lib/mongoid/safety.rb', line 38 def unsafely tap { Threaded. = false } end |