Sha256: 9c4de209e3667c2a4d4f1df3e2cd994763d41d8e83b09a438f95fbad2f933805
Contents?: true
Size: 1.77 KB
Versions: 190
Compression:
Stored size: 1.77 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Relations #:nodoc: module Referenced #:nodoc: module Batch #:nodoc: # Handles all the batch insert collection. class Insert attr_accessor :documents, :options # 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 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 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 def execute(collection) if collection && consumed? collection.insert(documents, options) end end end end end end end
Version data entries
190 entries across 98 versions & 5 rubygems