ehon 0.1.2 → 0.1.3

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: 7cfe34ca1049b454d6f6c9ad5901e9655f2154c4
4
- data.tar.gz: 3a036d5f298836e064c98d21d6a87f386797dbef
3
+ metadata.gz: f9c13a185fe95b0d199bf1410fbe6fe91dc802c7
4
+ data.tar.gz: ad8065fb8d46742bb40a972d5d638ea69c91170b
5
5
  SHA512:
6
- metadata.gz: 0e9d45b8c90d1c7d628fab88eadbcfd87f277fe3297b2f60b8c09fcf02038d60312dde8fd7ed14cf52de034860ae5a0537a9a12aba11aec9182992d53adeb6a9
7
- data.tar.gz: 827789868d73ed13b1f6e238b010cb9824ee9bcde60e60f8bffbf988a0f5051b8b1340bc9eea684abc212ccf526c4102bdf17b29a6d21d53933282c11f67df3f
6
+ metadata.gz: d234f5a6feb3ac2d85071a9e89135b87e30094ce7df8e09a1564d6cd01327a49c5e18880004b067bdf5d0dc73a074081543c6889285468ec99d179b3b1d478a6
7
+ data.tar.gz: 0761da4e00b3feae6c837a60cc3a9ead44450e2ea01c62e3cba202a6fd5c3dc6dadebbfa8a506e1c4a03633237d555e4c4ebc0d16bed1ea9b40d4fd09cc9b7d1
@@ -1,3 +1,7 @@
1
+ ## 0.1.3
2
+
3
+ * Add multiple returning item support
4
+
1
5
  ## 0.1.2
2
6
 
3
7
  * Add create_{accessors,readers,writers}! method
@@ -67,11 +67,16 @@ module Ehon
67
67
  queries.flatten!
68
68
  findeds = queries.map {|query|
69
69
  next self.contents[query] unless query.is_a?(Hash)
70
- self.contents.values.find {|instance|
70
+ self.contents.values.select {|instance|
71
71
  query.all? {|key, value| instance.read_attribute(key) == value }
72
72
  }
73
- }.compact
74
- queries.size == 1 ? findeds.first : findeds
73
+ }.flatten.compact
74
+ single = if queries.any? {|query| query.is_a?(Hash) }
75
+ queries.size == 1 && findeds.size <= 1
76
+ else
77
+ queries.size == 1
78
+ end
79
+ single ? findeds.first : findeds
75
80
  end
76
81
  alias [] find
77
82
 
@@ -1,3 +1,3 @@
1
1
  module Ehon
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -220,6 +220,7 @@ describe Ehon do
220
220
  subject.enum 1, name: 'potion', value: 5
221
221
  subject.enum 2, name: 'high potion', value: 10
222
222
  subject.enum '3', name: 'scroll'
223
+ subject.enum 4, name: 'stone', value: 5
223
224
  end
224
225
 
225
226
  context 'with key' do
@@ -255,8 +256,8 @@ describe Ehon do
255
256
  expect(finded.map(&:name)).to eq(['potion', 'high potion'])
256
257
  end
257
258
 
258
- it 'find with id [4, 8] should return empty array' do
259
- finded = subject.find([4, 8])
259
+ it 'find with id [5, 8] should return empty array' do
260
+ finded = subject.find([5, 8])
260
261
  expect(finded).to eq([])
261
262
  end
262
263
  end
@@ -267,9 +268,9 @@ describe Ehon do
267
268
  expect(finded.id).to eq(2)
268
269
  end
269
270
 
270
- it "find with `{value: 5}` should return item id 1" do
271
- finded = subject.find(value: 5)
272
- expect(finded.id).to eq(1)
271
+ it "find with `{value: 10}` should return item id 1" do
272
+ finded = subject.find(value: 10)
273
+ expect(finded.id).to eq(2)
273
274
  end
274
275
 
275
276
  it "find with `{id: '3'}` should return item id '3'" do
@@ -282,6 +283,11 @@ describe Ehon do
282
283
  expect(finded).to be_nil
283
284
  end
284
285
 
286
+ it 'find with `{value: 5}` should return 2 items' do
287
+ finded = subject.find(value: 5)
288
+ expect(finded.size).to eq(2)
289
+ end
290
+
285
291
  context 'AND search' do
286
292
  it "find with `{name: 'potion', value: 5}` should return item id 1" do
287
293
  finded = subject.find(name: 'potion', value: 5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Nishimura