class Mongoo::Persistence::RawUpdate

Attributes

criteria[RW]
opts[RW]
updates[RW]

Public Class Methods

new(doc) click to toggle source
# File lib/mongoo/persistence.rb, line 7
def initialize(doc)
  @doc = doc
  @criteria ||= {}
  @updates  ||= {}
  @opts     ||= {}
end

Public Instance Methods

run() click to toggle source
# 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) click to toggle source
# File lib/mongoo/persistence.rb, line 14
def will_change(&block)
  @will_change_block = block
end