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.
7 8 9 10 11 12 |
# File 'lib/mongoo/persistence.rb', line 7 def initialize(doc) @doc = doc @criteria ||= {} @updates ||= {} @opts ||= {} end |
Instance Attribute Details
#criteria ⇒ Object
Returns the value of attribute criteria.
5 6 7 |
# File 'lib/mongoo/persistence.rb', line 5 def criteria @criteria end |
#opts ⇒ Object
Returns the value of attribute opts.
5 6 7 |
# File 'lib/mongoo/persistence.rb', line 5 def opts @opts end |
#updates ⇒ Object
Returns the value of attribute updates.
5 6 7 |
# File 'lib/mongoo/persistence.rb', line 5 def updates @updates end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mongoo/persistence.rb', line 18 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
14 15 16 |
# File 'lib/mongoo/persistence.rb', line 14 def will_change(&block) @will_change_block = block end |