Class: Mongoo::Persistence::RawUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoo/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#criteriaObject

Returns the value of attribute criteria.



16
17
18
# File 'lib/mongoo/persistence.rb', line 16

def criteria
  @criteria
end

#optsObject

Returns the value of attribute opts.



16
17
18
# File 'lib/mongoo/persistence.rb', line 16

def opts
  @opts
end

#updatesObject

Returns the value of attribute updates.



16
17
18
# File 'lib/mongoo/persistence.rb', line 16

def updates
  @updates
end

Instance Method Details

#runObject



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