looksist 0.1.5 → 0.1.6

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: 52851b1abadfa5c5e0e753e84291b22643b25d21
4
- data.tar.gz: d6cde88e787c76b7a18048ceb7c968f0f9094f10
3
+ metadata.gz: f3d230c832c10ad4e4ee670fce558e6cf37a4dde
4
+ data.tar.gz: 84c37b806f565ac61a71ca9211e703f0dd5d8a9e
5
5
  SHA512:
6
- metadata.gz: 7e693cb1c71e42a59e51be1ae75e7c2d9830ca5289cef58cc5dc5f0123a743e558b0bd648600c2a6966a415354ccd065face0051f4b0e8747a791aad1827b286
7
- data.tar.gz: 563492167cc926ab5c282bb16c2e4473eee199c2a6152543ba8e725d15fe5a530db3ead9c8371925ff97ae0505a54c9cd9812a6b8d861cd87530c570efbdf760
6
+ metadata.gz: 9f7f97201af1469646f6c8dc50d833ce7973588ad41bde21c014c8dbf1c3e5d0787a5ad98bb9bf6a1dbd49897bb39e17295640ecadcc08bf1dd7a7b5322cc493
7
+ data.tar.gz: 4db2b2693cd497c1c11f1916c602bc71648f7064cf754e157f493995a67f56c951487ef215c836a2ef874aa46cd4157eb3ca411a867a145392c026c3c3fb8c4f
@@ -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 unless hash_offset
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)
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -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
- class EmptyResponse
211
- include Looksist
212
- def empty
213
- {}
214
- end
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
- expect(EmptyResponse.new.empty).to eq({})
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
- table: {
237
- menu: []
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.5
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-21 00:00:00.000000000 Z
12
+ date: 2014-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler