Module: Mongoid::Persistence::Operations
- Included in:
- Embedded::Insert, Embedded::Remove, Insert, Remove, Update
- Defined in:
- lib/mongoid/persistence/operations.rb,
lib/mongoid/persistence/operations/insert.rb,
lib/mongoid/persistence/operations/remove.rb,
lib/mongoid/persistence/operations/update.rb,
lib/mongoid/persistence/operations/embedded/insert.rb,
lib/mongoid/persistence/operations/embedded/remove.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Embedded Classes: Insert, Remove, Update
Instance Attribute Summary collapse
-
#conflicts ⇒ Object
readonly
Returns the value of attribute conflicts.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
-
.insert(doc, options = {}) ⇒ Operations
Get the appropriate insertion operation based on the document.
-
.remove(doc, options = {}) ⇒ Operations
Get the appropriate removal operation based on the document.
-
.update(doc, options = {}) ⇒ Operations
Get the appropriate update operation based on the document.
Instance Method Summary collapse
-
#collection ⇒ Collection
Get the collection we should be persisting to.
-
#deletes ⇒ Hash
Get the atomic delete operations for embedded documents.
-
#initialize(document, options = {}) ⇒ Object
Instantiate the new persistence operation.
-
#inserts ⇒ Hash
Get the atomic insert for embedded documents, either a push or set.
-
#notifying_parent? ⇒ true, false
Should the parent document (in the case of embedded persistence) be notified of the child deletion.
-
#options ⇒ Hash
Get all the options that will be sent to the database.
-
#parent ⇒ Document
Get the parent of the provided document.
-
#selector ⇒ Hash
Get the atomic selector for the document.
-
#updates ⇒ Hash
Get the atomic updates for the document without the conflicting modifications.
-
#validating? ⇒ true, false
Should we be running validations on this persistence operation? Defaults to true.
Instance Attribute Details
#conflicts ⇒ Object (readonly)
Returns the value of attribute conflicts.
15 16 17 |
# File 'lib/mongoid/persistence/operations.rb', line 15 def conflicts @conflicts end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
15 16 17 |
# File 'lib/mongoid/persistence/operations.rb', line 15 def document @document end |
Class Method Details
.insert(doc, options = {}) ⇒ Operations
Get the appropriate insertion operation based on the document.
190 191 192 |
# File 'lib/mongoid/persistence/operations.rb', line 190 def insert(doc, = {}) (doc. ? Embedded::Insert : Insert).new(doc, ) end |
.remove(doc, options = {}) ⇒ Operations
Get the appropriate removal operation based on the document.
175 176 177 |
# File 'lib/mongoid/persistence/operations.rb', line 175 def remove(doc, = {}) (doc. ? Embedded::Remove : Remove).new(doc, ) end |
.update(doc, options = {}) ⇒ Operations
Get the appropriate update operation based on the document.
205 206 207 |
# File 'lib/mongoid/persistence/operations.rb', line 205 def update(doc, = {}) Update.new(doc, ) end |
Instance Method Details
#collection ⇒ Collection
Get the collection we should be persisting to.
25 26 27 |
# File 'lib/mongoid/persistence/operations.rb', line 25 def collection @collection ||= document._root.collection end |
#deletes ⇒ Hash
Get the atomic delete operations for embedded documents.
37 38 39 40 41 |
# File 'lib/mongoid/persistence/operations.rb', line 37 def deletes { document.atomic_delete_modifier => { document.atomic_path => document._index ? { "_id" => document.id } : true } } end |
#initialize(document, options = {}) ⇒ Object
Instantiate the new persistence operation.
52 53 54 |
# File 'lib/mongoid/persistence/operations.rb', line 52 def initialize(document, = {}) @document, @options = document, end |
#inserts ⇒ Hash
Get the atomic insert for embedded documents, either a push or set.
64 65 66 67 |
# File 'lib/mongoid/persistence/operations.rb', line 64 def inserts { document.atomic_insert_modifier => { document.atomic_position => document.as_document } } end |
#notifying_parent? ⇒ true, false
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.
79 80 81 |
# File 'lib/mongoid/persistence/operations.rb', line 79 def @notifying_parent ||= !@options.delete(:suppress) end |
#options ⇒ Hash
Get all the options that will be sent to the database. Right now this is only safe mode opts.
92 93 94 |
# File 'lib/mongoid/persistence/operations.rb', line 92 def Safety.(@options) end |
#parent ⇒ Document
Get the parent of the provided document.
104 105 106 |
# File 'lib/mongoid/persistence/operations.rb', line 104 def parent document._parent end |
#selector ⇒ Hash
Get the atomic selector for the document.
116 117 118 |
# File 'lib/mongoid/persistence/operations.rb', line 116 def selector @selector ||= document.atomic_selector end |
#updates ⇒ Hash
Get the atomic updates for the document without the conflicting modifications.
129 130 131 |
# File 'lib/mongoid/persistence/operations.rb', line 129 def updates @updates ||= init_updates end |
#validating? ⇒ true, false
Should we be running validations on this persistence operation? Defaults to true.
142 143 144 |
# File 'lib/mongoid/persistence/operations.rb', line 142 def validating? @validating ||= @options[:validate].nil? ? true : @options[:validate] end |