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.



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

#criteriaObject

Returns the value of attribute criteria.



5
6
7
# File 'lib/mongoo/persistence.rb', line 5

def criteria
  @criteria
end

#optsObject

Returns the value of attribute opts.



5
6
7
# File 'lib/mongoo/persistence.rb', line 5

def opts
  @opts
end

#updatesObject

Returns the value of attribute updates.



5
6
7
# File 'lib/mongoo/persistence.rb', line 5

def updates
  @updates
end

Instance Method Details

#runObject



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