looksist 0.3.9 → 0.3.10
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/hashed.rb +6 -2
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +75 -47
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37c468cb360cd83c3a7ba117322fc4e14c45b17b
|
4
|
+
data.tar.gz: 1f0a60382362b5d5297f855ad642f8ff8c0accc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70cd16daa9cc9ee9d4d7f2e56b1e54807036831ce91d18f0caa16f1ed86cc84eac9191aee6b59794b013789ac453c38b334ec5a29b045704f92b9e3f9a37df22
|
7
|
+
data.tar.gz: 0d1358375f898228fa6276cc11221cb05867066b87a16fad1a5d7f82b1faff14af57285cf39cd00da4ac2981090eb817fb7de7cda2c06addd4b60475af814a1e
|
data/lib/looksist/hashed.rb
CHANGED
@@ -63,8 +63,12 @@ module Looksist
|
|
63
63
|
values = Looksist.redis_service.send("#{entity_name}_for", keys)
|
64
64
|
if opt[:populate].is_a? Array
|
65
65
|
opt[:populate].each do |elt|
|
66
|
-
|
67
|
-
|
66
|
+
if values.is_a?(Array)
|
67
|
+
value_hash = values.each_with_object([]) do |i, acc|
|
68
|
+
acc << JSON.parse(i || '{}').deep_symbolize_keys[elt]
|
69
|
+
end
|
70
|
+
else
|
71
|
+
value_hash = JSON.parse(values || '{}').deep_symbolize_keys[elt]
|
68
72
|
end
|
69
73
|
alias_method = find_alias(opt[:as], elt)
|
70
74
|
hash_offset[alias_method] = value_hash
|
data/lib/looksist/version.rb
CHANGED
@@ -151,11 +151,11 @@ describe Looksist::Hashed do
|
|
151
151
|
expect(@mock).to receive(:mget).with(*%w(employees/10 employees/20)).and_return(['emp 1', 'emp 2'])
|
152
152
|
|
153
153
|
expect(DeepHash.new.metrics).to eq({table: {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
inner_table: {
|
155
|
+
employee_id: [10, 20],
|
156
|
+
employee_name: ['emp 1', 'emp 2']
|
157
|
+
}
|
158
|
+
}})
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'should inject single attribute to an existing hash' do
|
@@ -176,9 +176,33 @@ describe Looksist::Hashed do
|
|
176
176
|
expect(@mock).to receive(:mget).with(*%w(employees/1 employees/2)).and_return(['emp 1', 'emp 2'])
|
177
177
|
|
178
178
|
expect(HashService1.new.metrics).to eq({table: {
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
employee_id: [1, 2],
|
180
|
+
employee_name: ['emp 1', 'emp 2']
|
181
|
+
}})
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should inject single attribute to an existing hash a without array' do
|
185
|
+
class HashServiceMulti
|
186
|
+
include Looksist
|
187
|
+
|
188
|
+
def metrics
|
189
|
+
{
|
190
|
+
table: {
|
191
|
+
employee_id: 1
|
192
|
+
}
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
196
|
+
inject after: :metrics, at: :table, using: :employee_id, populate: [:employee_name, :employer_gender]
|
197
|
+
end
|
198
|
+
|
199
|
+
expect(@mock).to receive(:get).with('employees/1').and_return({employee_name: 'emp 1', employer_gender: 'F'}.to_json)
|
200
|
+
|
201
|
+
expect(HashServiceMulti.new.metrics).to eq({table: {
|
202
|
+
employee_id: 1,
|
203
|
+
employee_name: 'emp 1',
|
204
|
+
employer_gender: 'F'
|
205
|
+
}})
|
182
206
|
end
|
183
207
|
|
184
208
|
it 'should inject multiple attribute to an existing hash' do
|
@@ -203,11 +227,11 @@ describe Looksist::Hashed do
|
|
203
227
|
expect(@mock).to receive(:mget).with(*%w(employers/3 employers/4)).and_return(['empr 3', 'empr 4'])
|
204
228
|
|
205
229
|
expect(HashService.new.metrics).to eq({table: {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
230
|
+
employee_id: [5, 6],
|
231
|
+
employer_id: [3, 4],
|
232
|
+
employee_name: ['emp 5', 'emp 6'],
|
233
|
+
employer_name: ['empr 3', 'empr 4']
|
234
|
+
}})
|
211
235
|
end
|
212
236
|
end
|
213
237
|
|
@@ -235,13 +259,13 @@ describe Looksist::Hashed do
|
|
235
259
|
expect(@mock).to receive(:mget).with(*%w(employers/13 employers/14)).and_return(['empr 13', 'empr 14'])
|
236
260
|
|
237
261
|
expect(EmployeeHash.new.metrics).to eq({table: {
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
262
|
+
database: {
|
263
|
+
employee_id: [15, 16],
|
264
|
+
employer_id: [13, 14],
|
265
|
+
employee_name: ['emp 15', 'emp 16'],
|
266
|
+
employer_name: ['empr 13', 'empr 14']
|
267
|
+
}
|
268
|
+
}})
|
245
269
|
end
|
246
270
|
|
247
271
|
context 'handle no data' do
|
@@ -324,14 +348,14 @@ describe Looksist::Hashed do
|
|
324
348
|
|
325
349
|
hash_service_super = HashServiceSuper.new
|
326
350
|
expect(hash_service_super.shrinkage).to eq({table: {
|
327
|
-
|
328
|
-
|
329
|
-
|
351
|
+
shrink_id: [1, 2],
|
352
|
+
shrink_name: ['shrink 1', 'shrink 2']
|
353
|
+
}})
|
330
354
|
|
331
355
|
expect(hash_service_super.stock).to eq({table: {
|
332
|
-
|
333
|
-
|
334
|
-
|
356
|
+
dc_id: [7, 8],
|
357
|
+
dc_name: ['dc 7', 'dc 8']
|
358
|
+
}})
|
335
359
|
end
|
336
360
|
end
|
337
361
|
end
|
@@ -365,11 +389,11 @@ describe Looksist::Hashed do
|
|
365
389
|
expect(@mock).to receive(:mget).with(*%w(employees/10)).and_return(['emp 1'])
|
366
390
|
|
367
391
|
expect(NoL2DeepHash.new.metrics).to eq({table: {
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
392
|
+
inner_table: {
|
393
|
+
employee_id: [10, 10],
|
394
|
+
employee_name: ['emp 1', 'emp 1']
|
395
|
+
}
|
396
|
+
}})
|
373
397
|
end
|
374
398
|
|
375
399
|
it 'should work for first level of substitution' do
|
@@ -399,11 +423,11 @@ describe Looksist::Hashed do
|
|
399
423
|
[
|
400
424
|
{
|
401
425
|
item_id: 1,
|
402
|
-
item_preference:'Low'
|
426
|
+
item_preference: 'Low'
|
403
427
|
},
|
404
428
|
{
|
405
429
|
item_id: 2,
|
406
|
-
item_preference:'High'
|
430
|
+
item_preference: 'High'
|
407
431
|
}
|
408
432
|
]
|
409
433
|
end
|
@@ -417,12 +441,12 @@ describe Looksist::Hashed do
|
|
417
441
|
[{
|
418
442
|
item_id: 1,
|
419
443
|
dish_name: 'Idly',
|
420
|
-
item_preference:'Low'
|
444
|
+
item_preference: 'Low'
|
421
445
|
},
|
422
446
|
{
|
423
447
|
item_id: 2,
|
424
448
|
dish_name: 'Pongal',
|
425
|
-
|
449
|
+
item_preference: 'High'
|
426
450
|
}]
|
427
451
|
)
|
428
452
|
|
@@ -585,9 +609,9 @@ describe Looksist::Hashed do
|
|
585
609
|
expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2 items/3)).and_return(jsons)
|
586
610
|
|
587
611
|
expect(ColumnarWithNil.metrics).to eq({:table => {:menu => {
|
588
|
-
|
589
|
-
|
590
|
-
|
612
|
+
:item_id => [1, 2, 2, 1, 1, 2, 3, 3, 2, 1],
|
613
|
+
:item_name => ['Rice Cake', 'Pan Cake', 'Pan Cake', 'Rice Cake', 'Rice Cake', 'Pan Cake', nil, nil, 'Pan Cake', 'Rice Cake'],
|
614
|
+
:item_mnemonic => ['Idly', 'Dosa', 'Dosa', 'Idly', 'Idly', 'Dosa', nil, nil, 'Dosa', 'Idly']}}})
|
591
615
|
|
592
616
|
expect(ColumnarWithEmpty.metrics).to eq({
|
593
617
|
table: {
|
@@ -600,38 +624,42 @@ describe Looksist::Hashed do
|
|
600
624
|
})
|
601
625
|
end
|
602
626
|
|
603
|
-
it'should work for nested injection for array of hash' do
|
627
|
+
it 'should work for nested injection for array of hash' do
|
604
628
|
class DeepLookUpAtArrayOfHash
|
605
629
|
include Looksist
|
630
|
+
|
606
631
|
def self.articles
|
607
632
|
[{:articles => [{:article_id => 1, :sub_category_id => 8001, :supplier_id => 158782, :sub_family_id => 18001}]}]
|
608
633
|
end
|
609
|
-
|
610
|
-
inject after: :articles, at:'$..articles', using: :
|
634
|
+
|
635
|
+
inject after: :articles, at: '$..articles', using: :article_id, populate: :name, as: {name: 'description'}
|
636
|
+
inject after: :articles, at: '$..articles', using: :sub_category_id, populate: :sub_category_name
|
611
637
|
end
|
612
638
|
|
613
639
|
expect(@mock).to receive(:mget).once.with(*%w(articles/1)).and_return(['A'])
|
614
640
|
expect(@mock).to receive(:mget).once.with(*%w(sub_categories/8001)).and_return(['B'])
|
615
641
|
|
616
|
-
expect(DeepLookUpAtArrayOfHash.articles).to eq([{:articles => [{:article_id => 1, :description=> 'A', :sub_category_id => 8001,
|
642
|
+
expect(DeepLookUpAtArrayOfHash.articles).to eq([{:articles => [{:article_id => 1, :description => 'A', :sub_category_id => 8001,
|
617
643
|
:sub_category_name => 'B',
|
618
644
|
:supplier_id => 158782, :sub_family_id => 18001}]}])
|
619
645
|
|
620
646
|
end
|
621
647
|
|
622
|
-
it'should work for nested injection for array of hash for multiple attributes' do
|
648
|
+
it 'should work for nested injection for array of hash for multiple attributes' do
|
623
649
|
class DeepLookUpAtArrayOfHashMultiple
|
624
650
|
include Looksist
|
651
|
+
|
625
652
|
def self.articles
|
626
653
|
[{:articles => [{:article_id => 1, :sub_category_id => 8001, :supplier_id => 158782, :sub_family_id => 18001}]}]
|
627
654
|
end
|
628
|
-
|
655
|
+
|
656
|
+
inject after: :articles, at: '$..articles', using: :article_id, populate: [:name, :weight]
|
629
657
|
end
|
630
658
|
|
631
|
-
expect(@mock).to receive(:mget).once.with(*%w(articles/1)).and_return([{name:'A', weight:1}.to_json])
|
659
|
+
expect(@mock).to receive(:mget).once.with(*%w(articles/1)).and_return([{name: 'A', weight: 1}.to_json])
|
632
660
|
|
633
|
-
expect(DeepLookUpAtArrayOfHashMultiple.articles).to eq([{:articles => [{:article_id => 1, :name=> 'A'
|
634
|
-
|
661
|
+
expect(DeepLookUpAtArrayOfHashMultiple.articles).to eq([{:articles => [{:article_id => 1, :name => 'A', :weight => 1, :sub_category_id => 8001,
|
662
|
+
:supplier_id => 158782, :sub_family_id => 18001}]}])
|
635
663
|
|
636
664
|
end
|
637
665
|
end
|
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.3.
|
4
|
+
version: 0.3.10
|
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-
|
12
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.
|
244
|
+
rubygems_version: 2.4.4
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: Redis backed lookup for your models
|