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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e78819a058a79be4256e3a0aeaf532ef3e679877
4
- data.tar.gz: af259c1e79e2956b8e6e1095108077469fd08038
3
+ metadata.gz: 7cd317f3b612baf2716008f1bddcc02381a9eaad
4
+ data.tar.gz: f773b200f9f8f75f5620184d3d28fafef7b09036
5
5
  SHA512:
6
- metadata.gz: 7a58b3d6500fe3030149da45066d8bad48a60eb26db5d61d3c2918955b3a8b467b1275418c99ab24f7b4fcaf40cdde17fe5fc8b44b98a8708d750d770b1116d1
7
- data.tar.gz: fbe8479ae3d03415816f4df902682943ae994a500566ba15f365f7e5c7ea5a9a04855e75d55b9ccdb9259fd9f84f6cc0620d0fd06df5a822956b07790707ea91
6
+ metadata.gz: 66d608fe08195ca9e61b6005f31f5792f7126c259785a48f9db2a57f6714a43fd86a572d80a586ecdeef232efcb710828ede3735b99929e8009ae6be0e073310
7
+ data.tar.gz: 0ad341af2a487c15c0737eee339404ab0b268d93e60898a3558678a2a0cd3f369df36ec8595f47b93ad0b175c45fd8865bca1e80ea2bf6ef14c77e315673bd2c
@@ -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 id
261
- id = _sanitize_id(id)
262
- tid = _is_type_prefixed? ? "#{_doc_type}::#{id}" : id
263
- result, _, cas = _default_db.get(tid, extended: true)
264
-
265
- result and
266
- type = result[:_type] || result["_type"] and
267
- type == _doc_type and
268
- new(result, id, cas) or
269
- nil
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
 
@@ -1,5 +1,5 @@
1
1
  module CouchPillow
2
2
  GEM_NAME = "couchpillow"
3
3
  NAME = "CouchPillow"
4
- VERSION = "0.4.7"
4
+ VERSION = "0.4.8"
5
5
  end
@@ -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.7
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-04-06 00:00:00.000000000 Z
11
+ date: 2015-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchbase