Parent

Class/Module Index [+]

Quicksearch

Mongoid::Atomic::Modifiers

This class contains the logic for supporting atomic operations against the database.

Public Instance Methods

add_to_set(modifications) click to toggle source

Add the atomic $addToSet modifiers to the hash.

@example Add the $addToSet modifiers.

modifiers.add_to_set({ "preference_ids" => [ "one" ] })

@param [ Hash ] modifications The add to set modifiers.

@since 2.4.0

# File lib/mongoid/atomic/modifiers.rb, line 16
def add_to_set(modifications)
  modifications.each_pair do |field, value|
    if add_to_sets.has_key?(field)
      value.each do |val|
        add_to_sets[field]["$each"].push(val)
      end
    else
      add_to_sets[field] = { "$each" => value }
    end
  end
end
pull(modifications) click to toggle source

Adds pull all modifiers to the modifiers hash.

@example Add pull all operations.

modifiers.pull({ "addresses" => { "_id" => { "$in" => [ 1, 2, 3 ]}}})

@param [ Hash ] modifications The pull all modifiers.

@since 3.0.0

# File lib/mongoid/atomic/modifiers.rb, line 51
def pull(modifications)
  modifications.each_pair do |field, value|
    pulls[field] = value
    pull_fields[field.split(".", 2)[0]] = field
  end
end
pull_all(modifications) click to toggle source

Adds pull all modifiers to the modifiers hash.

@example Add pull all operations.

modifiers.pull_all({ "addresses" => { "street" => "Bond" }})

@param [ Hash ] modifications The pull all modifiers.

@since 3.0.0

# File lib/mongoid/atomic/modifiers.rb, line 36
def pull_all(modifications)
  modifications.each_pair do |field, value|
    add_operation(pull_alls, field, value)
    pull_fields[field.split(".", 2)[0]] = field
  end
end
push(modifications) click to toggle source

Adds push modifiers to the modifiers hash.

@example Add push operations.

modifiers.push({ "addresses" => { "street" => "Bond" }})

@param [ Hash ] modifications The push modifiers.

@since 2.1.0

# File lib/mongoid/atomic/modifiers.rb, line 66
def push(modifications)
  modifications.each_pair do |field, value|
    push_fields[field] = field
    mods = push_conflict?(field) ? conflicting_pushes : pushes
    add_operation(mods, field, Array.wrap(value))
  end
end
set(modifications) click to toggle source

Adds set operations to the modifiers hash.

@example Add set operations.

modifiers.set({ "title" => "sir" })

@param [ Hash ] modifications The set modifiers.

@since 2.1.0

# File lib/mongoid/atomic/modifiers.rb, line 82
def set(modifications)
  modifications.each_pair do |field, value|
    next if field == "_id"
    mods = set_conflict?(field) ? conflicting_sets : sets
    add_operation(mods, field, value)
    set_fields[field.split(".", 2)[0]] = field
  end
end
unset(modifications) click to toggle source

Adds unset operations to the modifiers hash.

@example Add unset operations.

modifiers.unset([ "addresses" ])

@param [ Array<String> ] modifications The unset relation names.

@since 2.2.0

# File lib/mongoid/atomic/modifiers.rb, line 99
def unset(modifications)
  modifications.each do |field|
    unsets.update(field => true)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.