couchpillow 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/couchpillow/document.rb +16 -11
- data/lib/couchpillow/version.rb +1 -1
- data/test/test_document.rb +48 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd317f3b612baf2716008f1bddcc02381a9eaad
|
4
|
+
data.tar.gz: f773b200f9f8f75f5620184d3d28fafef7b09036
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d608fe08195ca9e61b6005f31f5792f7126c259785a48f9db2a57f6714a43fd86a572d80a586ecdeef232efcb710828ede3735b99929e8009ae6be0e073310
|
7
|
+
data.tar.gz: 0ad341af2a487c15c0737eee339404ab0b268d93e60898a3558678a2a0cd3f369df36ec8595f47b93ad0b175c45fd8865bca1e80ea2bf6ef14c77e315673bd2c
|
data/lib/couchpillow/document.rb
CHANGED
@@ -253,20 +253,25 @@ module CouchPillow
|
|
253
253
|
end
|
254
254
|
|
255
255
|
|
256
|
-
# Get a Document given an id.
|
256
|
+
# Get a Document given an id or multiple ids.
|
257
257
|
#
|
258
258
|
# @return nil if not found or Document is of a different type.
|
259
|
+
# If multiple ids are passed, returns an array.
|
259
260
|
#
|
260
|
-
def self.get
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
261
|
+
def self.get *ids
|
262
|
+
results = ids.map do |id|
|
263
|
+
id = _sanitize_id(id)
|
264
|
+
tid = _is_type_prefixed? ? "#{_doc_type}::#{id}" : id
|
265
|
+
result, _, cas = _default_db.get(tid, extended: true)
|
266
|
+
|
267
|
+
result and
|
268
|
+
type = result[:_type] || result["_type"] and
|
269
|
+
type == _doc_type and
|
270
|
+
new(result, id, cas) or
|
271
|
+
nil
|
272
|
+
end
|
273
|
+
|
274
|
+
results && results.size == 1 ? results.first : results
|
270
275
|
end
|
271
276
|
|
272
277
|
|
data/lib/couchpillow/version.rb
CHANGED
data/test/test_document.rb
CHANGED
@@ -242,6 +242,54 @@ class TestDocument < Minitest::Test
|
|
242
242
|
end
|
243
243
|
|
244
244
|
|
245
|
+
def test_get_multiple_ids
|
246
|
+
klass = Class.new(Document) do
|
247
|
+
type 'test'
|
248
|
+
attribute(:foo)
|
249
|
+
end
|
250
|
+
|
251
|
+
k = klass.new
|
252
|
+
k.foo = 100
|
253
|
+
k.save!
|
254
|
+
|
255
|
+
k2 = klass.new
|
256
|
+
k2.foo = 200
|
257
|
+
k2.save!
|
258
|
+
|
259
|
+
d = klass.get(k.id, k2.id)
|
260
|
+
assert_equal 2, d.size
|
261
|
+
assert_equal 100, d[0].foo
|
262
|
+
assert_equal 200, d[1].foo
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
def test_get_multiple_ids_different_types_and_nils
|
267
|
+
klassA = Class.new(Document) do
|
268
|
+
type 'klassA'
|
269
|
+
attribute(:foo)
|
270
|
+
end
|
271
|
+
|
272
|
+
klassB = Class.new(Document) do
|
273
|
+
type 'klassB'
|
274
|
+
attribute(:bar)
|
275
|
+
end
|
276
|
+
|
277
|
+
ka = klassA.new
|
278
|
+
ka.foo = 100
|
279
|
+
ka.save!
|
280
|
+
|
281
|
+
kb = klassB.new
|
282
|
+
kb.bar = 200
|
283
|
+
kb.save!
|
284
|
+
|
285
|
+
# kb is klassB, so it should be nil
|
286
|
+
d = klassA.get(kb.id, ka.id)
|
287
|
+
assert_equal 2, d.size
|
288
|
+
assert_nil d[0]
|
289
|
+
assert_equal 100, d[1].foo
|
290
|
+
end
|
291
|
+
|
292
|
+
|
245
293
|
def test_key_with_false_values
|
246
294
|
klass = Class.new(Document) do
|
247
295
|
attribute(:key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchpillow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Tedja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: couchbase
|