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 +4 -4
- data/lib/looksist/hashed.rb +11 -3
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +26 -0
- 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: d3b31dd61719b792195c63faf7e994b34d9464fd
|
4
|
+
data.tar.gz: 9506f4644e659ddb6c572539a79d0d6ece6f2996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eb15e84e6ab105097b844b34842acb1c30458a57c2763a6703cf0078ab5922939fe3ed37fd325703c4ccb4b807c08b3d135e6daa6e93fc630797059381b630e
|
7
|
+
data.tar.gz: 6254249ed2c52dcbb60fbe14190bae8d4538e6f89ffa9f8f79558dff7f65bb3cbc072ff9b8c44b3d1c0fcc64af77ac14a91128a485c972c0c8ca67b31c9c2826
|
data/lib/looksist/hashed.rb
CHANGED
@@ -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
|
-
|
62
|
-
|
63
|
-
|
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)
|
data/lib/looksist/version.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|