lib/upsert.rb
def row(selector, setter = {}, options = nil)
    row_object = Row.new(selector, setter, options)
    self.class.mutex_for_row(self, row_object).synchronize do
      merge_function(row_object).execute(row_object)
      nil
    end
  end
# Upsert a row given a selector and a setter.
#
# The selector values are used as setters if it's a new row. So if your selector is `name=Jerry` and your setter is `age=4`, and there is no Jerry yet, then a new row will be created with name Jerry and age 4.
#
# @see http://api.mongodb.org/ruby/1.6.4/Mongo/Collection.html#update-instance_method Loosely based on the upsert functionality of the mongo-ruby-driver #update method
#
# @param [Hash] selector Key-value pairs that will be used to find or create a row.
# @param [Hash] setter Key-value pairs that will be set on the row, whether it previously existed or not.
#
# @return [nil]
#
# @example One at a time
#   upsert = Upsert.new Pet.connection, Pet.table_name
#   upsert.row({:name => 'Jerry'}, :breed => 'beagle')
#   upsert.row({:name => 'Pierre'}, :breed => 'tabby')
Upsert a row given a selector and a setter.
The selector values are used as setters if it's a new row. So if your selector is `name=Jerry` and your setter is `age=4`, and there is no Jerry yet, then a new row will be created with name Jerry and age 4.
Upsert a row given a selector and a setter . The selector values are used as setters if it ' s a new row . So if your selector is ` name = Jerry ` and your setter is ` age = 4 ` and there is no Jerry yet then a new row will be created with name Jerry and age 4 .
def row(selector, setter = {}, options = nil)
    row_object = Row.new(selector, setter, options)
    self.class.mutex_for_row(self, row_object).synchronize do
      merge_function(row_object).execute(row_object)
      nil
    end
  end
def row ( selector , setter = { } , options = nil ) row_object = Row . new ( selector , setter , options ) self . class . mutex_for_row ( self , row_object ) . synchronize do merge_function ( row_object ) . execute ( row_object ) nil end end
Upsert a row given a selector and a setter.
Upsert a row given a selector and a setter .
None
nil
selector
setter
options
setter Key-value pairs that will be set on the row, whether it previously existed or not.
setter Key - value pairs that will be set on the row whether it previously existed or not .
see
api.mongodb.org/ruby/1.6.4/Mongo/Collection.html#update-instance_method Loosely based on the upsert functionality of the mongo-ruby-driver #update method
api . mongodb . org / ruby / 1 . 6 . 4 / Mongo / Collection . html#update - instance_method Loosely based on the upsert functionality of the mongo - ruby - driver #update method
example
One at a time upsert = Upsert.new Pet.connection, Pet.table_name upsert.row({:name => 'Jerry'}, :breed => 'beagle') upsert.row({:name => 'Pierre'}, :breed => 'tabby')
One at a time upsert = Upsert . new Pet . connection Pet . table_name upsert . row ( { : name = > ' Jerry ' } : breed = > ' beagle ' ) upsert . row ( { : name = > ' Pierre ' } : breed = > ' tabby ' )