looksist 0.1.1 → 0.1.2
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/lib/looksist/redis_service.rb +7 -5
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +10 -10
- data/spec/looksist/redis_service_spec.rb +11 -5
- 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: a968b111e81190b6beb211859660441fd85ce1a4
|
4
|
+
data.tar.gz: f77a551f75633ae29b2da166f57adcbbd0d5c725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb01d26875fd426930deb8a3edaf1b29e058747eff9a21b98462c71227e8d95e73cb8c5fd3ccf547441aa57d63450b20f83144c2698941ba8d59b32b33d4f62
|
7
|
+
data.tar.gz: 327be6f5250333bd497d3f6adc1f725f5636c43eca053c87fe1a63bdf789352a3887390f7d867a3d33d220a68e94bd99cee1fddeea7f3d21b3cf9ed172213ddc
|
@@ -16,8 +16,8 @@ module Looksist
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def method_missing(name, *args, &block)
|
19
|
-
if name.to_s.ends_with?(
|
20
|
-
entity = name.to_s.gsub('_for','')
|
19
|
+
if name.to_s.ends_with?('_for')
|
20
|
+
entity = name.to_s.gsub('_for', '')
|
21
21
|
first_arg = args.first
|
22
22
|
first_arg.is_a?(Array) ? find_all(entity, first_arg) : find(entity, first_arg)
|
23
23
|
else
|
@@ -35,8 +35,10 @@ module Looksist
|
|
35
35
|
raise 'Buffer overflow! Increase buffer size' if ids.length > @buffer_size
|
36
36
|
keys = ids.collect { |id| redis_key(entity, id) }
|
37
37
|
missed_keys = (keys - @cache.keys).uniq
|
38
|
-
|
39
|
-
|
38
|
+
unless missed_keys.empty?
|
39
|
+
values = @client.mget *missed_keys
|
40
|
+
@cache.merge!(Hash[*missed_keys.zip(values).flatten])
|
41
|
+
end
|
40
42
|
@cache.mslice(keys)
|
41
43
|
end
|
42
44
|
|
@@ -48,7 +50,7 @@ module Looksist
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def fetch(key, &block)
|
51
|
-
@cache[key] ||=
|
53
|
+
@cache[key] ||= block.call
|
52
54
|
end
|
53
55
|
|
54
56
|
def redis_key(entity, id)
|
data/lib/looksist/version.rb
CHANGED
@@ -33,8 +33,8 @@ describe Looksist::Hashed do
|
|
33
33
|
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: :item_name
|
34
34
|
end
|
35
35
|
|
36
|
-
expect(@mock).to receive(:mget).with(['items/1']).and_return(['Idly'])
|
37
|
-
expect(@mock).to receive(:mget).with(['items/2']).and_return(['Pongal'])
|
36
|
+
expect(@mock).to receive(:mget).with(*['items/1']).and_return(['Idly'])
|
37
|
+
expect(@mock).to receive(:mget).with(*['items/2']).and_return(['Pongal'])
|
38
38
|
|
39
39
|
expect(Menu.new.metrics).to eq({
|
40
40
|
table: {
|
@@ -110,7 +110,7 @@ describe Looksist::Hashed do
|
|
110
110
|
inject after: :metrics, at: '$.table.inner_table', using: :employee_id, populate: :employee_name
|
111
111
|
end
|
112
112
|
|
113
|
-
expect(@mock).to receive(:mget).with(
|
113
|
+
expect(@mock).to receive(:mget).with(*%w(employees/10 employees/20)).and_return(['emp 1', 'emp 2'])
|
114
114
|
|
115
115
|
expect(DeepHash.new.metrics).to eq({table: {
|
116
116
|
inner_table: {
|
@@ -135,7 +135,7 @@ describe Looksist::Hashed do
|
|
135
135
|
inject after: :metrics, at: :table, using: :employee_id, populate: :employee_name
|
136
136
|
end
|
137
137
|
|
138
|
-
expect(@mock).to receive(:mget).with(
|
138
|
+
expect(@mock).to receive(:mget).with(*%w(employees/1 employees/2)).and_return(['emp 1', 'emp 2'])
|
139
139
|
|
140
140
|
expect(HashService1.new.metrics).to eq({table: {
|
141
141
|
employee_id: [1, 2],
|
@@ -160,9 +160,9 @@ describe Looksist::Hashed do
|
|
160
160
|
inject after: :metrics, at: :table, using: :employer_id, populate: :employer_name
|
161
161
|
end
|
162
162
|
|
163
|
-
expect(@mock).to receive(:mget).with(
|
163
|
+
expect(@mock).to receive(:mget).with(*%w(employees/5 employees/6)).and_return(['emp 5', 'emp 6'])
|
164
164
|
|
165
|
-
expect(@mock).to receive(:mget).with(
|
165
|
+
expect(@mock).to receive(:mget).with(*%w(employers/3 employers/4)).and_return(['empr 3', 'empr 4'])
|
166
166
|
|
167
167
|
expect(HashService.new.metrics).to eq({table: {
|
168
168
|
employee_id: [5, 6],
|
@@ -192,9 +192,9 @@ describe Looksist::Hashed do
|
|
192
192
|
inject after: :metrics, at: '$.table.database', using: :employer_id, populate: :employer_name
|
193
193
|
end
|
194
194
|
|
195
|
-
expect(@mock).to receive(:mget).with(
|
195
|
+
expect(@mock).to receive(:mget).with(*%w(employees/15 employees/16)).and_return(['emp 15', 'emp 16'])
|
196
196
|
|
197
|
-
expect(@mock).to receive(:mget).with(
|
197
|
+
expect(@mock).to receive(:mget).with(*%w(employers/13 employers/14)).and_return(['empr 13', 'empr 14'])
|
198
198
|
|
199
199
|
expect(EmployeeHash.new.metrics).to eq({table: {
|
200
200
|
database: {
|
@@ -267,9 +267,9 @@ describe Looksist::Hashed do
|
|
267
267
|
inject after: :stock, at: :table, using: :dc_id, populate: :dc_name
|
268
268
|
end
|
269
269
|
|
270
|
-
expect(@mock).to receive(:mget).with(
|
270
|
+
expect(@mock).to receive(:mget).with(*%w(shrinks/1 shrinks/2)).and_return(['shrink 1', 'shrink 2'])
|
271
271
|
|
272
|
-
expect(@mock).to receive(:mget).with(
|
272
|
+
expect(@mock).to receive(:mget).with(*%w(dcs/7 dcs/8)).and_return(['dc 7', 'dc 8'])
|
273
273
|
|
274
274
|
hash_service_super = HashServiceSuper.new
|
275
275
|
expect(hash_service_super.shrinkage).to eq({table: {
|
@@ -39,14 +39,20 @@ describe Looksist::RedisService do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should mget redis when there are multiple keys' do
|
42
|
-
expect(@mock).to receive(:mget).with(
|
42
|
+
expect(@mock).to receive(:mget).with('snacks/1', 'snacks/2', 'snacks/3').once.and_return(%w(BAJJI BONDA VADA))
|
43
43
|
expect(@lookup.snacks_for([1, 2, 3])).to match_array(%w(BAJJI BONDA VADA))
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should mget redis only for unique keys' do
|
47
|
-
expect(@mock).to receive(:mget).with(
|
47
|
+
expect(@mock).to receive(:mget).with('snacks/1', 'snacks/2', 'snacks/3').once.and_return(%w(BAJJI BONDA VADA))
|
48
48
|
expect(@lookup.snacks_for([1, 2, 3, 1, 2])).to match_array(%w(BAJJI BONDA VADA BAJJI BONDA))
|
49
49
|
end
|
50
|
+
|
51
|
+
it 'should get from cache' do
|
52
|
+
expect(@mock).to receive(:mget).with('snacks/1', 'snacks/2', 'snacks/3', 'snacks/4', 'snacks/5').once.and_return(%w(BAJJI BONDA VADA MEDU_VADA MASALA_VADA))
|
53
|
+
expect(@lookup.snacks_for([1, 2, 3, 4, 5])).to match_array(%w(BAJJI BONDA VADA MEDU_VADA MASALA_VADA))
|
54
|
+
expect(@lookup.snacks_for([1, 2, 3, 4, 5])).to match_array(%w(BAJJI BONDA VADA MEDU_VADA MASALA_VADA))
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
context 'value not present' do
|
@@ -59,8 +65,8 @@ describe Looksist::RedisService do
|
|
59
65
|
end
|
60
66
|
|
61
67
|
it 'should not bomb when there are no values present' do
|
62
|
-
expect(@mock).to receive(:mget).with(
|
63
|
-
expect(@lookup.snacks_for([1, 2, 3])).to match_array([
|
68
|
+
expect(@mock).to receive(:mget).with('snacks/1', 'snacks/2', 'snacks/3').once.and_return(['BAJJI', nil, 'VADA'])
|
69
|
+
expect(@lookup.snacks_for([1, 2, 3])).to match_array(['BAJJI', nil, 'VADA'])
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
@@ -74,7 +80,7 @@ describe Looksist::RedisService do
|
|
74
80
|
end
|
75
81
|
|
76
82
|
it 'should clear the local cache' do
|
77
|
-
expect(@mock).to receive(:mget).with(
|
83
|
+
expect(@mock).to receive(:mget).with('snacks/1', 'snacks/2', 'snacks/3').once.and_return(['BAJJI', nil, 'VADA'])
|
78
84
|
@lookup.snacks_for([1, 2, 3])
|
79
85
|
expect(@lookup.cache.size).to eq(3)
|
80
86
|
@lookup.flush_cache!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: looksist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RC
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|