Sha256: 939adced4c98b5adde0d7dd50681f9317f6e6c9033bcbf2d0f679c64a146a3d6

Contents?: true

Size: 804 Bytes

Versions: 2

Compression:

Stored size: 804 Bytes

Contents

require 'pathname'
require 'rubygems'
require 'bundler'

Bundler.require(:default)

root_path = Pathname(__FILE__).dirname.join('..').expand_path
lib_path  = root_path.join('lib')
$:.unshift(lib_path)

require 'toy/mongo'

class User
  include Toy::Mongo
  include Toy::Mongo::AtomicUpdates

  adapter :mongo_atomic, Mongo::Connection.new.db('adapter')['testing']

  attribute :name, String
  attribute :bio, String
end

user = User.create(:name => 'John', :bio => 'Awesome!')
puts user.name # John
puts user.bio  # Awesome!

# simulate another process updating only bio
user.adapter.client.update({:_id => user.id}, '$set' => {:bio => "Changed!"})

user.name = 'Nunes'
user.save # save performs update with $set's rather than full doc save

user.reload

puts user.name # Nunes
puts user.bio  # Changed!

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
toystore-mongo-0.12.0 examples/atomic_updates.rb
toystore-mongo-0.11.0 examples/atomic_updates.rb