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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3b31dd61719b792195c63faf7e994b34d9464fd
4
- data.tar.gz: 9506f4644e659ddb6c572539a79d0d6ece6f2996
3
+ metadata.gz: c9e223a56fa500fbab484ad09eb23888d21ba0e4
4
+ data.tar.gz: c9e15de4a77e2f64a0458bb4f9a05fd89127c22f
5
5
  SHA512:
6
- metadata.gz: 9eb15e84e6ab105097b844b34842acb1c30458a57c2763a6703cf0078ab5922939fe3ed37fd325703c4ccb4b807c08b3d135e6daa6e93fc630797059381b630e
7
- data.tar.gz: 6254249ed2c52dcbb60fbe14190bae8d4538e6f89ffa9f8f79558dff7f65bb3cbc072ff9b8c44b3d1c0fcc64af77ac14a91128a485c972c0c8ca67b31c9c2826
6
+ metadata.gz: e29215c24a0879bd9c971539d52d4c34d109de530d9f53d6488fd10a333af560b79e32c01defa2c7775b33c73380f35fe24bb225c6eb553ee6b028866a59b27a
7
+ data.tar.gz: c6bbf9e15bea1037dc15f4223503992392144e023a98c80db915c20af9d8ad0263c9c260ad94f936b877d4891d5d7254bdd860e1ec04c4cfaf88ceab9ff5db7b
@@ -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([]) { |i, acc| acc << JSON.parse(i).deep_symbolize_keys[elt] }
64
- alias_method = find_alias(opts, elt)
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
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -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], :name=>["Rice Cake", "Rice pudding"], :mnemonic=>["Idly", "Pongal"]}}})
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
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC