Parent

Class/Module Index [+]

Quicksearch

Mongoid::Relations::Referenced::Batch::Insert

Handles all the batch insert collection.

Attributes

documents[RW]
options[RW]

Public Instance Methods

consume(document, options = {}) click to toggle source

Consumes an execution that was supposed to hit the database, but is now being deferred to later in favor of a single batch insert.

@example Consume the operation.

set.consume({ "field" => "value" }, { :safe => true })

@param [ Hash ] document The document to collect. @param [ Hash ] options The persistence options.

@option options [ true, false ] :safe Persist in safe mode.

@since 2.0.2, batch-relational-insert

# File lib/mongoid/relations/referenced/batch/insert.rb, line 22
def consume(document, options = {})
  @consumed, @options = true, options
  (@documents ||= []).push(document)
end
consumed?() click to toggle source

Has this operation consumed any executions?

@example Is this consumed?

insert.consumed?

@return [ true, false ] If the operation has consumed anything.

@since 2.0.2, batch-relational-insert

# File lib/mongoid/relations/referenced/batch/insert.rb, line 35
def consumed?
  !!@consumed
end
execute(collection) click to toggle source

Execute the batch insert operation on the collection.

@example Execute the operation.

insert.execute(collection)

@param [ Collection ] collection The root collection.

@since 2.0.2, batch-relational-insert

# File lib/mongoid/relations/referenced/batch/insert.rb, line 47
def execute(collection)
  if collection && consumed?
    collection.insert(documents, options)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.