looksist 0.1.5 → 0.1.6
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 +3 -2
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +24 -11
- 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: f3d230c832c10ad4e4ee670fce558e6cf37a4dde
|
4
|
+
data.tar.gz: 84c37b806f565ac61a71ca9211e703f0dd5d8a9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7f97201af1469646f6c8dc50d833ce7973588ad41bde21c014c8dbf1c3e5d0787a5ad98bb9bf6a1dbd49897bb39e17295640ecadcc08bf1dd7a7b5322cc493
|
7
|
+
data.tar.gz: 4db2b2693cd497c1c11f1916c602bc71648f7064cf754e157f493995a67f56c951487ef215c836a2ef874aa46cd4157eb3ca411a867a145392c026c3c3fb8c4f
|
data/lib/looksist/hashed.rb
CHANGED
@@ -21,7 +21,8 @@ module Looksist
|
|
21
21
|
self.class.instance_variable_get(:@rules)[after].each do |opts|
|
22
22
|
if opts[:at].is_a? String
|
23
23
|
hash = JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
|
24
|
-
i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts)
|
24
|
+
i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless i.empty?
|
25
|
+
i
|
25
26
|
end.to_hash.deep_symbolize_keys
|
26
27
|
else
|
27
28
|
inject_attributes_at(hash[opts[:at]], opts)
|
@@ -41,7 +42,7 @@ module Looksist
|
|
41
42
|
private
|
42
43
|
|
43
44
|
def inject_attributes_at(hash_offset, opts)
|
44
|
-
return nil
|
45
|
+
return hash_offset if hash_offset.nil? or hash_offset.empty?
|
45
46
|
keys = hash_offset[opts[:using]]
|
46
47
|
entity_name = __entity__(opts[:using])
|
47
48
|
values = Looksist.redis_service.send("#{entity_name}_for", keys)
|
data/lib/looksist/version.rb
CHANGED
@@ -207,14 +207,27 @@ describe Looksist::Hashed do
|
|
207
207
|
|
208
208
|
context 'handle no data' do
|
209
209
|
it 'should not inject when data is not available' do
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
inject after: :empty, at: :'$.table', using: :subcat_id, populate: :sub_cat_name
|
210
|
+
class EmptyResponse
|
211
|
+
include Looksist
|
212
|
+
|
213
|
+
def empty
|
214
|
+
{:high_stock => {}, :low_shelf_life => {}, :in_elimination => {}, :inactive_with_stock => {}}
|
216
215
|
end
|
217
|
-
|
216
|
+
|
217
|
+
inject after: :empty, at: :high_stock,
|
218
|
+
using: :sub_category_id, populate: :sub_category
|
219
|
+
|
220
|
+
inject after: :empty, at: '$.low_shelf_life',
|
221
|
+
using: :sub_category_id, populate: :sub_category
|
222
|
+
|
223
|
+
inject after: :empty, at: '$.in_elimination',
|
224
|
+
using: :sub_category_id, populate: :sub_category
|
225
|
+
|
226
|
+
inject after: :empty, at: '$.inactive_with_stock',
|
227
|
+
using: :sub_category_id, populate: :sub_category
|
228
|
+
end
|
229
|
+
expected_response = {:high_stock => {}, :low_shelf_life => {}, :in_elimination => {}, :inactive_with_stock => {}}
|
230
|
+
expect(EmptyResponse.new.empty).to eq(expected_response)
|
218
231
|
end
|
219
232
|
|
220
233
|
it 'should be capable to deep lookup and inject' do
|
@@ -233,10 +246,10 @@ describe Looksist::Hashed do
|
|
233
246
|
end
|
234
247
|
|
235
248
|
expect(EmptyMenu.new.metrics).to eq({
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
249
|
+
table: {
|
250
|
+
menu: []
|
251
|
+
}
|
252
|
+
})
|
240
253
|
end
|
241
254
|
end
|
242
255
|
|
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.1.
|
4
|
+
version: 0.1.6
|
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-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|