looksist 0.0.5 → 0.0.6

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: 030f8794b73dd763721680befd241cb03ec7accd
4
- data.tar.gz: d2733173bbe4358c815292d6688f9b3a0e9605b4
3
+ metadata.gz: 47127df0b135086ad1b95ee199d088314c50f83c
4
+ data.tar.gz: 198c22a471345cc532722857028da3606c6391e7
5
5
  SHA512:
6
- metadata.gz: c40ccf107034ee352a64e22da82c4c481b0b1bff0fec2ae856bc6a7386ec57ceb2d9d4ba608c9ac614fc7d957d79a150f4ab342f2c9738b064e4cd39277282c6
7
- data.tar.gz: a56ca3e2de786acdf5189258ca5ae744b5b28456aecb2d0228c54e46c7bf4395d7d4883636cf06c98564e6d46a823e277a149ee6951cfacb6b61e32f0e5b5347
6
+ metadata.gz: e58ac9cddc8cca41531ba83705e1943599a6873071f484689edc73c384dbf909a4936eebed6965336ff4efa79f27d35f28cfeab3c8ab916e6709d79c9d492bb1
7
+ data.tar.gz: 34ef32317da4f0fd82c7524b87c90dc56c44cb7dd9bff680830d9cd04ec6a6de9b9b5c5cc7cf7b3dcf9c3fcf9d6755d6292b979cf702af521ee45ccbfeaa924d
@@ -23,7 +23,7 @@ module Looksist
23
23
  self.class.instance_variable_get(:@rules)[opts[:after]].each do |opts|
24
24
  if opts[:at].is_a? String
25
25
  hash = JsonPath.for(hash.with_indifferent_access).gsub(opts[:at]) do |i|
26
- inject_attributes_at(i, opts)
26
+ i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts)
27
27
  end.to_hash.deep_symbolize_keys
28
28
  else
29
29
  inject_attributes_at(hash[opts[:at]], opts)
@@ -51,5 +51,14 @@ module Looksist
51
51
  hash_offset[opts[:populate]] = values
52
52
  hash_offset
53
53
  end
54
+
55
+ def inject_attributes_for(arry_of_hashes, opts)
56
+ arry_of_hashes.each do |elt|
57
+ key = elt[opts[:using]]
58
+ entity_name = entity(opts[:using])
59
+ value = Hashed.redis_service.send("#{entity_name}_for", [key])
60
+ elt[opts[:populate]] = value.first
61
+ end
62
+ end
54
63
  end
55
64
  end
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/spec/hashed_spec.rb CHANGED
@@ -17,7 +17,94 @@ describe Looksist::Hashed do
17
17
 
18
18
 
19
19
  context 'inject ' do
20
+
20
21
  it 'should be capable to deep lookup and inject' do
22
+ class Menu
23
+ include Looksist::Hashed
24
+
25
+ def metrics
26
+ {
27
+ table: {
28
+ menu: [
29
+ {
30
+ item_id: 1
31
+ },
32
+ {
33
+ item_id: 2
34
+ }
35
+ ]
36
+ }
37
+ }
38
+ end
39
+
40
+ inject after: :metrics, at: '$.table.menu', using: :item_id, populate: :item_name
41
+ end
42
+
43
+ expect(@mock).to receive(:get).with('items/1').and_return(OpenStruct.new(value: 'Idly'))
44
+ expect(@mock).to receive(:get).with('items/2').and_return(OpenStruct.new(value: 'Pongal'))
45
+
46
+ expect(Menu.new.metrics).to eq(
47
+ {
48
+ table: {
49
+ menu: [
50
+ {
51
+ item_id: 1,
52
+ item_name: 'Idly'
53
+ },
54
+ {
55
+ item_id: 2,
56
+ item_name: 'Pongal'
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ )
62
+ end
63
+
64
+ xit 'should be capable to deep lookup and inject - another example' do
65
+ class NewMenu
66
+ include Looksist::Hashed
67
+
68
+ def metrics
69
+ {
70
+ table: {
71
+ menu: [
72
+ {
73
+ item_id: 4,
74
+ item_name: 'Idly'
75
+ },
76
+ {
77
+ item_id: 5
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ end
83
+
84
+ inject after: :metrics, at: '$.table.menu[?(@.item_id=5)]', using: :item_id, populate: :item_name
85
+ end
86
+
87
+ expect(@mock).to receive(:get).with('items/5').and_return(OpenStruct.new(value: 'Pongal'))
88
+
89
+ expect(NewMenu.new.metrics).to eq(
90
+ {
91
+ table: {
92
+ menu: [
93
+ {
94
+ item_id: 4,
95
+ item_name: 'Idly'
96
+ },
97
+ {
98
+ item_id: 5,
99
+ item_name: 'Pongal'
100
+ }
101
+ ]
102
+ }
103
+ }
104
+ )
105
+ end
106
+
107
+ it 'should be capable to deep lookup and inject on columnar hashes' do
21
108
  class DeepHash
22
109
  include Looksist::Hashed
23
110
 
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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC