Sha256: 3e081d36355ec62fb0d64f4de13832f1063bc31948cb96c64450a23f2966f19b
Contents?: true
Size: 1.99 KB
Versions: 193
Compression:
Stored size: 1.99 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Relations #:nodoc: module Embedded #:nodoc: module Atomic #:nodoc: class Operation attr_accessor :documents, :options, :path, :selector # Consumes an execution that was supposed to hit the database, but is # now being deferred to later in favor of a single update. # # @example Consume the operation. # set.consume( # { "_id" => BSON::ObjectId.new }, # { "$push" => { "addresses" => { "_id" => "street" } } }, # { :multi => false, :safe => true } # ) # # @param [ Hash ] selector The document selector. # @param [ Hash ] operations The ops to set in the db. # @param [ Hash ] options The persistence options. # # @option options [ true, false ] :multi Persist multiple at once. # @option options [ true, false ] :safe Persist in safe mode. # # @since 2.0.0 def consume(selector, operations, options = {}) @consumed, @selector, @options = true, selector, options @documents ||= [] parse(operations) end # Has this operation consumed any executions? # # @example Is this consumed? # unset.consumed? # # @return [ true, false ] If the operation has consumed anything. # # @since 2.0.0 def consumed? !!@consumed end # Execute the $pushAll operation on the collection. # # @example Execute the operation. # unset.execute(collection) # # @param [ Collection ] collection The root collection. # # @since 2.0.0 def execute(collection) if collection && consumed? collection.update(selector, operations, options) end end end end end end end
Version data entries
193 entries across 101 versions & 5 rubygems