Module: Mongoid::Persistence::Operations
- Included in:
- Embedded::Insert, Embedded::Remove, Insert, Remove, Update, Upsert
- 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/upsert.rb,
lib/mongoid/persistence/operations/embedded/insert.rb,
lib/mongoid/persistence/operations/embedded/remove.rb
Overview
Persistence operations include this module to get basic functionality on initialization.
Defined Under Namespace
Modules: Embedded Classes: Insert, Remove, Update, Upsert
Instance Attribute Summary collapse
-
#conflicts ⇒ Object
readonly
Returns the value of attribute conflicts.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
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.
-
.upsert(doc, options = {}) ⇒ Operations
Get the appropriate upsert 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.
-
#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.
16 17 18 |
# File 'lib/mongoid/persistence/operations.rb', line 16 def conflicts @conflicts end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
16 17 18 |
# File 'lib/mongoid/persistence/operations.rb', line 16 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/mongoid/persistence/operations.rb', line 16 def @options end |
Class Method Details
.insert(doc, options = {}) ⇒ Operations
Get the appropriate insertion operation based on the document.
178 179 180 |
# File 'lib/mongoid/persistence/operations.rb', line 178 def insert(doc, = {}) (doc. ? Embedded::Insert : Insert).new(doc, ) end |
.remove(doc, options = {}) ⇒ Operations
Get the appropriate removal operation based on the document.
163 164 165 |
# File 'lib/mongoid/persistence/operations.rb', line 163 def remove(doc, = {}) (doc. ? Embedded::Remove : Remove).new(doc, ) end |
.update(doc, options = {}) ⇒ Operations
Get the appropriate update operation based on the document.
193 194 195 |
# File 'lib/mongoid/persistence/operations.rb', line 193 def update(doc, = {}) Update.new(doc, ) end |
.upsert(doc, options = {}) ⇒ Operations
Get the appropriate upsert operation based on the document.
208 209 210 |
# File 'lib/mongoid/persistence/operations.rb', line 208 def upsert(doc, = {}) Upsert.new(doc, ) end |
Instance Method Details
#collection ⇒ Collection
Get the collection we should be persisting to.
26 27 28 |
# File 'lib/mongoid/persistence/operations.rb', line 26 def collection @collection ||= document._root.collection end |
#deletes ⇒ Hash
Get the atomic delete operations for embedded documents.
38 39 40 41 42 |
# File 'lib/mongoid/persistence/operations.rb', line 38 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.
53 54 55 |
# File 'lib/mongoid/persistence/operations.rb', line 53 def initialize(document, = {}) @document, @options = document, end |
#inserts ⇒ Hash
Get the atomic insert for embedded documents, either a push or set.
65 66 67 68 |
# File 'lib/mongoid/persistence/operations.rb', line 65 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.
80 81 82 |
# File 'lib/mongoid/persistence/operations.rb', line 80 def @notifying_parent ||= !@options.delete(:suppress) end |
#parent ⇒ Document
Get the parent of the provided document.
92 93 94 |
# File 'lib/mongoid/persistence/operations.rb', line 92 def parent document._parent end |
#selector ⇒ Hash
Get the atomic selector for the document.
104 105 106 |
# File 'lib/mongoid/persistence/operations.rb', line 104 def selector @selector ||= document.atomic_selector end |
#updates ⇒ Hash
Get the atomic updates for the document without the conflicting modifications.
117 118 119 |
# File 'lib/mongoid/persistence/operations.rb', line 117 def updates @updates ||= init_updates end |
#validating? ⇒ true, false
Should we be running validations on this persistence operation? Defaults to true.
130 131 132 |
# File 'lib/mongoid/persistence/operations.rb', line 130 def validating? @validating ||= @options[:validate].nil? ? true : @options[:validate] end |