Permalink
Browse files

Update CAS value after mutation

Change-Id: I5bccb77f8d6cf3868ae20a0058307364d3560b97
Reviewed-on: http://review.couchbase.org/21343
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
1 parent 5219afc commit 3ca8e4a063a3b8b4cb0551aacd6c2991ec4d4513 @avsej committed Oct 4, 2012
Showing with 15 additions and 2 deletions.
  1. +15 −2 lib/couchbase/model.rb
View
@@ -463,7 +463,13 @@ def initialize(attrs = {})
def create
@id ||= Couchbase::Model::UUID.generator.next(1, model.thread_storage[:uuid_algorithm])
value = @_raw ? @_raw : attributes_with_values
- model.bucket.add(@id, value, model.defaults)
+ unless @meta
+ @meta = {}
+ if @meta.respond_to?(:with_indifferent_access)
+ @meta = @meta.with_indifferent_access
+ end
+ end
+ @meta['cas'] = model.bucket.add(@id, value, model.defaults)
self
end
@@ -484,7 +490,13 @@ def save(cas = nil)
end
return create unless meta
value = @_raw ? @_raw : attributes_with_values
- model.bucket.replace(@id, value, model.defaults.merge(:cas => cas))
+ unless @meta
+ @meta = {}
+ if @meta.respond_to?(:with_indifferent_access)
+ @meta = @meta.with_indifferent_access
+ end
+ end
+ @meta['cas'] = model.bucket.replace(@id, value, model.defaults.merge(:cas => cas))
self
end
@@ -517,6 +529,7 @@ def delete(cas = nil)
raise Couchbase::Error::MissingId, "missing id attribute" unless @id
model.bucket.delete(@id)
@id = nil
+ @meta = nil
self
end

0 comments on commit 3ca8e4a

Please sign in to comment.