ehon 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ehon.rb +8 -3
- data/lib/ehon/version.rb +1 -1
- data/spec/ehon_spec.rb +11 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c13a185fe95b0d199bf1410fbe6fe91dc802c7
|
4
|
+
data.tar.gz: ad8065fb8d46742bb40a972d5d638ea69c91170b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d234f5a6feb3ac2d85071a9e89135b87e30094ce7df8e09a1564d6cd01327a49c5e18880004b067bdf5d0dc73a074081543c6889285468ec99d179b3b1d478a6
|
7
|
+
data.tar.gz: 0761da4e00b3feae6c837a60cc3a9ead44450e2ea01c62e3cba202a6fd5c3dc6dadebbfa8a506e1c4a03633237d555e4c4ebc0d16bed1ea9b40d4fd09cc9b7d1
|
data/CHANGELOG.md
CHANGED
data/lib/ehon.rb
CHANGED
@@ -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.
|
70
|
+
self.contents.values.select {|instance|
|
71
71
|
query.all? {|key, value| instance.read_attribute(key) == value }
|
72
72
|
}
|
73
|
-
}.compact
|
74
|
-
|
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
|
|
data/lib/ehon/version.rb
CHANGED
data/spec/ehon_spec.rb
CHANGED
@@ -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 [
|
259
|
-
finded = subject.find([
|
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:
|
271
|
-
finded = subject.find(value:
|
272
|
-
expect(finded.id).to eq(
|
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)
|