Class: Mongoid::Atomic::Modifiers

Inherits:
Hash show all
Defined in:
lib/mongoid/atomic/modifiers.rb

Overview

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

Instance Method Summary collapse

Methods included from Extensions::Hash::Scoping

#scoped

Methods included from Extensions::Hash::CriteriaHelpers

#expand_complex_criteria, #extract_id

Instance Method Details

#pull(modifications) ⇒ Object

Adds pull modifiers to the modifiers hash.

Examples:

Add pull operations.

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

Parameters:

  • modifications (Hash)

    The pull modifiers.

Since:

  • 2.2.0



17
18
19
20
21
22
# File 'lib/mongoid/atomic/modifiers.rb', line 17

def pull(modifications)
  modifications.each_pair do |field, value|
    add_operation(pulls, field, value)
    pull_fields << field.split(".", 2)[0]
  end
end

#push(modifications) ⇒ Object

Adds push modifiers to the modifiers hash.

Examples:

Add push operations.

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

Parameters:

  • modifications (Hash)

    The push modifiers.

Since:

  • 2.1.0



32
33
34
35
36
37
# File 'lib/mongoid/atomic/modifiers.rb', line 32

def push(modifications)
  modifications.each_pair do |field, value|
    mods = push_conflict?(field) ? conflicting_pushes : pushes
    add_operation(mods, field, Array.wrap(value))
  end
end

#set(modifications) ⇒ Object

Adds set operations to the modifiers hash.

Examples:

Add set operations.

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

Parameters:

  • modifications (Hash)

    The set modifiers.

Since:

  • 2.1.0



47
48
49
50
51
52
53
54
# File 'lib/mongoid/atomic/modifiers.rb', line 47

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]
  end
end

#unset(modifications) ⇒ Object

Adds unset operations to the modifiers hash.

Examples:

Add unset operations.

modifiers.unset([ "addresses" ])

Parameters:

  • modifications (Array<String>)

    The unset relation names.

Since:

  • 2.2.0



64
65
66
67
68
# File 'lib/mongoid/atomic/modifiers.rb', line 64

def unset(modifications)
  modifications.each do |field|
    unsets.update(field => true)
  end
end