Module: Mongoid::Safety::ClassMethods

Defined in:
lib/mongoid/safety.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#safely(safety = true) ⇒ Proxy

Execute the following class-level persistence operation in safe mode.

Examples:

Create in safe mode.

Person.safely.create(:name => "John")

Delete all in safe mode with options.

Person.safely(:w => 2, :fsync => true).delete_all

Parameters:

  • options (Hash)

    The safe mode options.

Returns:

  • (Proxy)

    The safety proxy.



86
87
88
# File 'lib/mongoid/safety.rb', line 86

def safely(safety = true)
  tap { Threaded.safety_options = safety }
end

#unsafelyProxy

Execute the following class-level persistence operation without safe mode. Allows per-request overriding of safe mode when the persist_in_safe_mode config option is turned on.

Examples:

Upsert in safe mode.

Person.unsafely.create(:name => "John")

Returns:

  • (Proxy)

    The safety proxy.

Since:

  • 2.3.0



100
101
102
# File 'lib/mongoid/safety.rb', line 100

def unsafely
  tap { Threaded.safety_options = false }
end