looksist 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53a388186cedd458e2dab2eecb8b05e9351c81a4
4
- data.tar.gz: 9709f69d2f4ba76a3f3ef6e24e04d5f74d628c0d
3
+ metadata.gz: d3b31dd61719b792195c63faf7e994b34d9464fd
4
+ data.tar.gz: 9506f4644e659ddb6c572539a79d0d6ece6f2996
5
5
  SHA512:
6
- metadata.gz: 4ccc8051b94102c289c1e5a9463707ef559e7d82ab0e2a35fb11730ac5977dd8bab91c1a09a31caf45fc013d5e28e0804d158b91e15c2e273aff34fc04dab536
7
- data.tar.gz: 9af59f885b033c6f8da30ad4d0faba4edc3d305cce38ba5cff2758ed4a0954ae72573cba46196a8156ac64992d4867212f5bf80dd5c296d94c70891f20bde724
6
+ metadata.gz: 9eb15e84e6ab105097b844b34842acb1c30458a57c2763a6703cf0078ab5922939fe3ed37fd325703c4ccb4b807c08b3d135e6daa6e93fc630797059381b630e
7
+ data.tar.gz: 6254249ed2c52dcbb60fbe14190bae8d4538e6f89ffa9f8f79558dff7f65bb3cbc072ff9b8c44b3d1c0fcc64af77ac14a91128a485c972c0c8ca67b31c9c2826
@@ -58,9 +58,17 @@ module Looksist
58
58
  keys = hash_offset[opts[:using]]
59
59
  entity_name = __entity__(opts[:bucket_name] || opts[:using])
60
60
  values = Looksist.redis_service.send("#{entity_name}_for", keys)
61
- alias_method = find_alias(opts, opts[:populate])
62
- hash_offset[alias_method] = values
63
- hash_offset
61
+ if opts[:populate].is_a? Array
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)
65
+ hash_offset[alias_method] = value_hash
66
+ end
67
+ else
68
+ alias_method = find_alias(opts, opts[:populate])
69
+ hash_offset[alias_method] = values
70
+ hash_offset
71
+ end
64
72
  end
65
73
 
66
74
  def update_using_json_path(hash, opts)
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -490,5 +490,31 @@ describe Looksist::Hashed do
490
490
  expect(FirstLevelClass.my_method).to eq({:a => 1, :name => "RajiniKanth"})
491
491
  end
492
492
 
493
+ it 'should be capable to deep lookup and inject multiple attributes' do
494
+ class DeepLookUpMultiple
495
+ include Looksist
496
+
497
+ def self.metrics
498
+ {
499
+ table: {
500
+ menu:{
501
+ item_id: [1,2]
502
+ }
503
+ }
504
+ }
505
+ end
506
+
507
+ inject after: :metrics, at: '$.table.menu', using: :item_id, populate: [:name, :mnemonic]
508
+ end
509
+
510
+ js1 = {name: 'Rice Cake', mnemonic: 'Idly'}.to_json
511
+ js2 = {name: 'Rice pudding', mnemonic: 'Pongal'}.to_json
512
+ jsons = [js1, js2]
513
+
514
+ expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2)).and_return(jsons)
515
+
516
+ expect(DeepLookUpMultiple.metrics).to eq({:table => {:menu=>{:item_id=>[1, 2], :name=>["Rice Cake", "Rice pudding"], :mnemonic=>["Idly", "Pongal"]}}})
517
+ end
518
+
493
519
  end
494
520
  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.2
4
+ version: 0.3.3
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-30 00:00:00.000000000 Z
12
+ date: 2014-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler