Class: Mongoid::Persistence::Atomic::Operation

Inherits:
Object
  • Object
show all
Includes:
Safe
Defined in:
lib/mongoid/persistence/atomic/operation.rb

Overview

This is the superclass for all atomic operation objects.

Direct Known Subclasses

AddToSet, Inc, PullAll, Push

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Safe

#safe_mode?

Constructor Details

#initialize(document, field, value, options = {}) ⇒ Operation

Initialize the new pullAll operation.

Examples:

Create a new pullAll operation.

PullAll.new(document, :aliases, [ "Bond" ])

Parameters:

  • document (Document)

    The document to pullAll onto.

  • field (Symbol)

    The name of the array field.

  • value (Object)

    The value to pullAll.

  • options (Hash) (defaults to: {})

    The persistence options.

Since:

  • 2.0.0



23
24
25
26
# File 'lib/mongoid/persistence/atomic/operation.rb', line 23

def initialize(document, field, value, options = {})
  @document, @field, @value = document, field, value
  @options = { :safe => safe_mode?(options) }
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



10
11
12
# File 'lib/mongoid/persistence/atomic/operation.rb', line 10

def document
  @document
end

#fieldObject (readonly)

Returns the value of attribute field.



10
11
12
# File 'lib/mongoid/persistence/atomic/operation.rb', line 10

def field
  @field
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/mongoid/persistence/atomic/operation.rb', line 10

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/mongoid/persistence/atomic/operation.rb', line 10

def value
  @value
end

Instance Method Details

#operation(modifier) ⇒ Hash

Get the atomic operation to perform.

Examples:

Get the operation.

inc.operation

Parameters:

  • modifier (String)

    The modifier to use.

Returns:

  • (Hash)

    The atomic operation for the field and addition.

Since:

  • 2.0.0



38
39
40
# File 'lib/mongoid/persistence/atomic/operation.rb', line 38

def operation(modifier)
  { modifier => { field => value } }
end