Class/Module Index [+]

Quicksearch

Mongoid::Safety

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.

Public Instance Methods

safely(safety = true) click to toggle source

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

@example Upsert in safe mode.

person.safely.upsert

@example Destroy in safe mode with w and fsync options.

person.safely(:w => 2, :fsync => true).destroy

@param [ Hash ] options The safe mode options.

@option options [ Integer ] :w The number of nodes to write to. @option options [ Integer ] :wtimeout Time to wait for return from all

nodes.

@option options [ true, false ] :fsync Should a fsync occur.

@return [ Proxy ] The safety proxy.

# File lib/mongoid/safety.rb, line 25
def safely(safety = true)
  tap { Threaded.safety_options = safety }
end
unsafely() click to toggle source

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.

@example Upsert in safe mode.

person.unsafely.upsert

@return [ Proxy ] The safety proxy.

# File lib/mongoid/safety.rb, line 37
def unsafely
  tap { Threaded.safety_options = false }
end

Public Class Methods

merge_safety_options(options = {}) click to toggle source

Static class method of easily getting the desired safe mode options from anywhere in the framework.

@example Get the options with safe mode included.

Safety.merge_safety_options({ :safe => false })

@param [ Hash ] options The persistence options.

@return [ Hash ] The options hash.

@since 2.1.0

# File lib/mongoid/safety.rb, line 54
def merge_safety_options(options = {})
  options ||= {}
  return options if options[:safe]

  unless Threaded.safety_options.nil?
    safety = Threaded.safety_options
  else
    safety = Mongoid.persist_in_safe_mode
  end
  options.merge!({ :safe => safety })
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.