Persistence operations include this module to get basic functionality on initialization.
Get the collection we should be persisting to.
@example Get the collection.
operation.collection
@return [ Collection ] The collection to persist to.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 24 def collection @collection ||= document._root.collection end
Get the atomic delete operations for embedded documents.
@example Get the atomic deletes.
operation.deletes
@return [ Hash ] The atomic delete selector.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 36 def deletes { document.atomic_delete_modifier => { document.atomic_path => document._index ? { "_id" => document.id } : true } } end
Get the atomic insert for embedded documents, either a push or set.
@example Get the inserts.
operation.inserts
@return [ Hash ] The insert ops.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 63 def inserts { document.atomic_insert_modifier => { document.atomic_position => document.as_document } } end
Should the parent document (in the case of embedded persistence) be notified of the child deletion. This is used when calling delete from the associations themselves.
@example Should the parent be notified?
operation.notifying_parent?
@return [ true, false ] If the parent should be notified.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 78 def notifying_parent? @notifying_parent ||= !@options.delete(:suppress) end
Get all the options that will be sent to the database. Right now this is only safe mode opts.
@example Get the options hash.
operation.options
@return [ Hash ] The options for the database.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 91 def options Safety.merge_safety_options(@options) end
Get the parent of the provided document.
@example Get the parent.
operation.parent
@return [ Document ] The parent document.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 103 def parent document._parent end
Get the atomic selector for the document.
@example Get the selector.
operation.selector.
@return [ Hash ] The mongodb selector.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 115 def selector @selector ||= document.atomic_selector end
Get the atomic updates for the document without the conflicting modifications.
@example Get the atomic updates.
operation.updates
@return [ Hash ] The updates sans conflicting mods.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 128 def updates @updates ||= init_updates end
Should we be running validations on this persistence operation? Defaults to true.
@example Run validations?
operation.validating?
@return [ true, false ] If we run validations.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 141 def validating? @validating ||= @options[:validate].nil? ? true : @options[:validate] end
Instantiate the new persistence operation.
@example Create the operation.
Operation.new(document, { :safe => true }, { "field" => "value" })
@param [ Document ] document The document to persist. @param [ Hash ] options The persistence options.
@since 2.1.0
# File lib/mongoid/persistence/operations.rb, line 51 def initialize(document, options = {}) @document, @options = document, options end
Generated with the Darkfish Rdoc Generator 2.