Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow optional CAS value for mutators

Change-Id: I699b893383879b122d2086352a67add06020b02c
  • Loading branch information...
commit d6c879d916e89180b292cd4dcf81c246ef7609dc 1 parent 7ac873c
@avsej authored
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/couchbase/model.rb
View
13 lib/couchbase/model.rb
@@ -447,15 +447,16 @@ def create
#
# @since 0.0.1
#
+ # @param [Bignum] cas CAS value
# @return [Couchbase::Model] The saved object
#
# @example Update the Post model
# p = Post.find('hello-world')
# p.draft = false
# p.save
- def save
+ def save(cas = nil)
return create if new?
- model.bucket.set(@id, attributes_with_values)
+ model.bucket.set(@id, attributes_with_values, :cas => cas)
self
end
@@ -465,10 +466,11 @@ def save
#
# @param [Hash] attrs Attribute value pairs to use for the updated
# version
+ # @param [Bignum] cas CAS value
# @return [Couchbase::Model] The updated object
- def update(attrs)
+ def update(attrs, cas = nil)
update_attributes(attrs)
- save
+ save(cas)
end
# Delete this object from the bucket
@@ -477,12 +479,13 @@ def update(attrs)
#
# @note This method will reset +id+ attribute
#
+ # @param [Bignum] cas CAS value
# @return [Couchbase::Model] Returns a reference of itself.
#
# @example Delete the Post model
# p = Post.find('hello-world')
# p.delete
- def delete
+ def delete(cas = nil)
raise Couchbase::Error::MissingId, "missing id attribute" unless @id
model.bucket.delete(@id)
@id = nil

0 comments on commit d6c879d

Please sign in to comment.
Something went wrong with that request. Please try again.