looksist 0.3.3 → 0.3.4
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 +9 -3
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +54 -2
- 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: c9e223a56fa500fbab484ad09eb23888d21ba0e4
|
4
|
+
data.tar.gz: c9e15de4a77e2f64a0458bb4f9a05fd89127c22f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e29215c24a0879bd9c971539d52d4c34d109de530d9f53d6488fd10a333af560b79e32c01defa2c7775b33c73380f35fe24bb225c6eb553ee6b028866a59b27a
|
7
|
+
data.tar.gz: c6bbf9e15bea1037dc15f4223503992392144e023a98c80db915c20af9d8ad0263c9c260ad94f936b877d4891d5d7254bdd860e1ec04c4cfaf88ceab9ff5db7b
|
data/lib/looksist/hashed.rb
CHANGED
@@ -60,12 +60,18 @@ module Looksist
|
|
60
60
|
values = Looksist.redis_service.send("#{entity_name}_for", keys)
|
61
61
|
if opts[:populate].is_a? Array
|
62
62
|
opts[:populate].each do |elt|
|
63
|
-
value_hash = values.each_with_object([])
|
64
|
-
|
63
|
+
value_hash = values.each_with_object([]) do |i, acc|
|
64
|
+
if i.nil?
|
65
|
+
acc << nil
|
66
|
+
else
|
67
|
+
acc << JSON.parse(i).deep_symbolize_keys[elt]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
alias_method = find_alias(opts[:as], elt)
|
65
71
|
hash_offset[alias_method] = value_hash
|
66
72
|
end
|
67
73
|
else
|
68
|
-
alias_method = find_alias(opts, opts[:populate])
|
74
|
+
alias_method = find_alias(opts[:as], opts[:populate])
|
69
75
|
hash_offset[alias_method] = values
|
70
76
|
hash_offset
|
71
77
|
end
|
data/lib/looksist/version.rb
CHANGED
@@ -504,7 +504,7 @@ describe Looksist::Hashed do
|
|
504
504
|
}
|
505
505
|
end
|
506
506
|
|
507
|
-
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: [:name, :mnemonic]
|
507
|
+
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: [:name, :mnemonic], as: {name:'item_name', mnemonic:'item_mnemonic'}
|
508
508
|
end
|
509
509
|
|
510
510
|
js1 = {name: 'Rice Cake', mnemonic: 'Idly'}.to_json
|
@@ -513,7 +513,59 @@ describe Looksist::Hashed do
|
|
513
513
|
|
514
514
|
expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2)).and_return(jsons)
|
515
515
|
|
516
|
-
expect(DeepLookUpMultiple.metrics).to eq({:table => {:menu=>{:item_id=>[1, 2], :
|
516
|
+
expect(DeepLookUpMultiple.metrics).to eq({:table => {:menu=>{:item_id=>[1, 2], :item_name=>["Rice Cake", "Rice pudding"], :item_mnemonic=>["Idly", "Pongal"]}}})
|
517
|
+
end
|
518
|
+
|
519
|
+
it 'should be capable to deep lookup and inject multiple attributes ignoring nil values' do
|
520
|
+
class DeepLookUpMultipleIngnorNil
|
521
|
+
include Looksist
|
522
|
+
|
523
|
+
def self.metrics
|
524
|
+
{
|
525
|
+
table: {
|
526
|
+
menu:{
|
527
|
+
item_id: [1,2]
|
528
|
+
}
|
529
|
+
}
|
530
|
+
}
|
531
|
+
end
|
532
|
+
|
533
|
+
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: [:name, :mnemonic], as: {name:'item_name', mnemonic:'item_mnemonic'}
|
534
|
+
end
|
535
|
+
|
536
|
+
js1 = {name: 'Rice Cake', mnemonic: 'Idly'}.to_json
|
537
|
+
jsons = [js1, nil]
|
538
|
+
|
539
|
+
expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2)).and_return(jsons)
|
540
|
+
|
541
|
+
expect(DeepLookUpMultipleIngnorNil.metrics).to eq({:table => {:menu=>{:item_id=>[1, 2], :item_name=>["Rice Cake", nil], :item_mnemonic=>["Idly", nil]}}})
|
542
|
+
end
|
543
|
+
|
544
|
+
it 'should be capable to deep lookup and inject multiple attributes in same order' do
|
545
|
+
class ColumnarWithNil
|
546
|
+
include Looksist
|
547
|
+
|
548
|
+
def self.metrics
|
549
|
+
{
|
550
|
+
table: {
|
551
|
+
menu:{
|
552
|
+
item_id: [1,2,2,1,1,2,3,3,2,1]
|
553
|
+
}
|
554
|
+
}
|
555
|
+
}
|
556
|
+
end
|
557
|
+
|
558
|
+
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: [:name, :mnemonic], as: {name:'item_name', mnemonic:'item_mnemonic'}
|
559
|
+
end
|
560
|
+
|
561
|
+
js1 = {name: 'Rice Cake', mnemonic: 'Idly'}.to_json
|
562
|
+
js2 = {name: 'Pan Cake', mnemonic: 'Dosa'}.to_json
|
563
|
+
jsons = [js1, js2, nil]
|
564
|
+
|
565
|
+
expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2 items/3)).and_return(jsons)
|
566
|
+
|
567
|
+
expect(ColumnarWithNil.metrics).to eq({:table => {:menu=>{:item_id=>[1,2,2,1,1,2,3,3,2,1], :item_name=>["Rice Cake", "Pan Cake", "Pan Cake", "Rice Cake", "Rice Cake", "Pan Cake", nil, nil, "Pan Cake", "Rice Cake"],
|
568
|
+
:item_mnemonic=>["Idly", "Dosa","Dosa","Idly","Idly","Dosa", nil,nil, "Dosa", "Idly" ]}}})
|
517
569
|
end
|
518
570
|
|
519
571
|
end
|