Class: Mongoo::Persistence::RawUpdate
- Inherits:
-
Object
- Object
- Mongoo::Persistence::RawUpdate
- Defined in:
- lib/mongoo/persistence.rb
Instance Attribute Summary collapse
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#updates ⇒ Object
Returns the value of attribute updates.
Instance Method Summary collapse
-
#initialize(doc) ⇒ RawUpdate
constructor
A new instance of RawUpdate.
- #run ⇒ Object
- #will_change(&block) ⇒ Object
Constructor Details
#initialize(doc) ⇒ RawUpdate
Returns a new instance of RawUpdate.
18 19 20 21 22 23 |
# File 'lib/mongoo/persistence.rb', line 18 def initialize(doc) @doc = doc @criteria ||= {} @updates ||= {} @opts ||= {} end |
Instance Attribute Details
#criteria ⇒ Object
Returns the value of attribute criteria.
16 17 18 |
# File 'lib/mongoo/persistence.rb', line 16 def criteria @criteria end |
#opts ⇒ Object
Returns the value of attribute opts.
16 17 18 |
# File 'lib/mongoo/persistence.rb', line 16 def opts @opts end |
#updates ⇒ Object
Returns the value of attribute updates.
16 17 18 |
# File 'lib/mongoo/persistence.rb', line 16 def updates @updates end |
Instance Method Details
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoo/persistence.rb', line 29 def run @criteria.stringify_keys! @criteria["_id"] = @doc.id ret = @doc.collection.update(self.criteria, self.updates, self.opts) if !ret.is_a?(Hash) || (ret["updatedExisting"] && ret["n"] == 1) if @will_change_block @will_change_block.call(@doc, ret) end end ret end |
#will_change(&block) ⇒ Object
25 26 27 |
# File 'lib/mongoo/persistence.rb', line 25 def will_change(&block) @will_change_block = block end |