couchbase-model 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.markdown +4 -0
- data/lib/couchbase/model.rb +34 -19
- data/lib/couchbase/model/version.rb +1 -1
- metadata +2 -2
data/HISTORY.markdown
CHANGED
data/lib/couchbase/model.rb
CHANGED
@@ -163,6 +163,14 @@ module Couchbase
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
def self.defaults(options = nil)
|
167
|
+
if options
|
168
|
+
@_defaults = options
|
169
|
+
else
|
170
|
+
@_defaults || {}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
166
174
|
# Ensure that design document is up to date.
|
167
175
|
#
|
168
176
|
# @since 0.1.0
|
@@ -224,7 +232,7 @@ module Couchbase
|
|
224
232
|
end
|
225
233
|
|
226
234
|
doc['views'].delete_if {|_, v| v.empty? }
|
227
|
-
doc.delete('spatial') if doc['spatial'].empty?
|
235
|
+
doc.delete('spatial') if doc['spatial'] && doc['spatial'].empty?
|
228
236
|
doc['signature'] = digest.to_s
|
229
237
|
doc['timestamp'] = mtime
|
230
238
|
if doc['signature'] != thread_storage[:signature] && doc['timestamp'] > thread_storage[:timestamp].to_i
|
@@ -406,23 +414,28 @@ module Couchbase
|
|
406
414
|
#
|
407
415
|
# @param [Hash] attrs attribute-value pairs
|
408
416
|
def initialize(attrs = {})
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
417
|
+
case attrs
|
418
|
+
when Hash, HashWithIndifferentAccess
|
419
|
+
if attrs.respond_to?(:with_indifferent_access)
|
420
|
+
attrs = attrs.with_indifferent_access
|
421
|
+
end
|
422
|
+
@id = attrs.delete(:id)
|
423
|
+
@key = attrs.delete(:key)
|
424
|
+
@value = attrs.delete(:value)
|
425
|
+
@doc = attrs.delete(:doc)
|
426
|
+
@meta = attrs.delete(:meta)
|
427
|
+
@_attributes = ::Hash.new do |h, k|
|
428
|
+
default = self.class.attributes[k]
|
429
|
+
h[k] = if default.respond_to?(:call)
|
430
|
+
default.call
|
431
|
+
else
|
432
|
+
default
|
433
|
+
end
|
434
|
+
end
|
435
|
+
update_attributes(@doc || attrs)
|
436
|
+
else
|
437
|
+
@_raw = attrs
|
424
438
|
end
|
425
|
-
update_attributes(@doc || attrs)
|
426
439
|
end
|
427
440
|
|
428
441
|
# Create this model and assign new id if necessary
|
@@ -439,7 +452,8 @@ module Couchbase
|
|
439
452
|
# p.create
|
440
453
|
def create
|
441
454
|
@id ||= Couchbase::Model::UUID.generator.next(1, model.thread_storage[:uuid_algorithm])
|
442
|
-
|
455
|
+
value = @_raw ? @_raw : attributes_with_values
|
456
|
+
model.bucket.add(@id, value, model.defaults)
|
443
457
|
self
|
444
458
|
end
|
445
459
|
|
@@ -456,7 +470,8 @@ module Couchbase
|
|
456
470
|
# p.save
|
457
471
|
def save(cas = nil)
|
458
472
|
return create if new?
|
459
|
-
|
473
|
+
value = @_raw ? @_raw : attributes_with_values
|
474
|
+
model.bucket.replace(@id, value, model.default.merge(:cas => cas))
|
460
475
|
self
|
461
476
|
end
|
462
477
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchbase-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: couchbase
|