frozen_record 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frozen_record/index.rb +20 -1
- data/lib/frozen_record/version.rb +1 -1
- data/spec/scope_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d75dfc07a86429e4dcc6a17c076aa87081a19e812b3d9b8d9722281d8a14aba9
|
4
|
+
data.tar.gz: a445c878d8cddaa87cb59db1213cf4099e3cbf10fa854d92fbd28669867dad4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b3c787e7c0f028c8c58a2a1fb214a5b3ac0c4b8b06ac4a42d4a35526baa0c50573967a7aa7faad0921c028d19d985dda831257f2244b1ba5af56960187ced1
|
7
|
+
data.tar.gz: 8159f7e45d32256ab9565bbf5ff81c6685e912c57603f97b335f8c5dbb2529b4153bb0e2937e4c709da9a78d0f303f485e33daf4933aa129be9599313964ec8d
|
data/lib/frozen_record/index.rb
CHANGED
@@ -20,6 +20,19 @@ module FrozenRecord
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def query(value)
|
23
|
+
case value
|
24
|
+
when Array, Range
|
25
|
+
lookup_multi(value)
|
26
|
+
else
|
27
|
+
lookup(value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def lookup_multi(values)
|
32
|
+
values.flat_map { |v| lookup(v) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def lookup(value)
|
23
36
|
@index.fetch(value, EMPTY_ARRAY)
|
24
37
|
end
|
25
38
|
|
@@ -42,7 +55,13 @@ module FrozenRecord
|
|
42
55
|
true
|
43
56
|
end
|
44
57
|
|
45
|
-
def
|
58
|
+
def lookup_multi(values)
|
59
|
+
results = @index.values_at(*values)
|
60
|
+
results.compact!
|
61
|
+
results
|
62
|
+
end
|
63
|
+
|
64
|
+
def lookup(value)
|
46
65
|
record = @index[value]
|
47
66
|
record ? [record] : EMPTY_ARRAY
|
48
67
|
end
|
data/spec/scope_spec.rb
CHANGED
@@ -207,6 +207,14 @@ describe 'querying' do
|
|
207
207
|
countries = Country.where(name: 'France', continent: 'Europe')
|
208
208
|
expect(countries.length).to be == 1
|
209
209
|
end
|
210
|
+
|
211
|
+
it 'can use indices with inclusion query' do
|
212
|
+
countries = Country.where(continent: ['Europe', 'North America'])
|
213
|
+
expect(countries.length).to be == 3
|
214
|
+
|
215
|
+
countries = Country.where(name: ['France', 'Canada'])
|
216
|
+
expect(countries.length).to be == 2
|
217
|
+
end
|
210
218
|
end
|
211
219
|
|
212
220
|
describe '.where.not' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.19.
|
4
|
+
version: 0.19.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|