Object
Handles all the batch insert collection.
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
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 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
Generated with the Darkfish Rdoc Generator 2.