Module: Mongo::WriteConcern

Included in:
Collection, DB, GridIO, MongoClient
Defined in:
lib/mongo/util/write_concern.rb

Constant Summary collapse

@@safe_warn =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#legacy_write_concernObject (readonly)

Returns the value of attribute legacy_write_concern.



4
5
6
# File 'lib/mongo/util/write_concern.rb', line 4

def legacy_write_concern
  @legacy_write_concern
end

Class Method Details

.gle?(write_concern) ⇒ Boolean



44
45
46
47
48
49
50
51
# File 'lib/mongo/util/write_concern.rb', line 44

def self.gle?(write_concern)
  (write_concern[:w].is_a? Symbol) ||
  (write_concern[:w].is_a? String) ||
  write_concern[:w] > 0 ||
  write_concern[:j] ||
  write_concern[:fsync] ||
  write_concern[:wtimeout]
end

Instance Method Details

#get_write_concern(opts, parent = nil) ⇒ Object

todo: throw exception for conflicting write concern options



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mongo/util/write_concern.rb', line 31

def get_write_concern(opts, parent=nil)
  write_concern_from_legacy(opts) if opts.key?(:safe) || @legacy_write_concern
  write_concern = {
    :w        => 1,
    :j        => false,
    :fsync    => false,
    :wtimeout => nil
  }
  write_concern.merge!(parent.write_concern) if parent
  write_concern.merge!(opts.reject {|k,v| !write_concern.keys.include?(k)})
  write_concern
end

#write_concern_from_legacy(opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mongo/util/write_concern.rb', line 7

def write_concern_from_legacy(opts)
  # Warn if 'safe' parameter is being used,
  if opts.key?(:safe) && !@@safe_warn && !ENV['TEST_MODE']
    warn "[DEPRECATED] The 'safe' write concern option has been deprecated in favor of 'w'."
    @@safe_warn = true
  end

  # nil:   set :w => 0
  # false: set :w => 0
  # true:  set :w => 1
  # hash:  set :w => 0 and merge with opts

  unless opts.has_key?(:w)
    opts[:w] = 0 # legacy default, unacknowledged
    safe     = opts.delete(:safe)
    if(safe && safe.is_a?(Hash))
      opts.merge!(safe)
    elsif(safe == true)
      opts[:w] = 1
    end
  end
end