looksist 0.2.8 → 0.2.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a94198209689c7f7d3ab46c70ea437e34aa94ec9
|
4
|
+
data.tar.gz: 371c038b94dcf344047530fcebb5dbc0ea06851c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8adf4a7ba0580561c474dac05c47bbd4b31bc9f7567f26a8ed88a94b002af699b3b989957bf0ea550f6fe7fd16445dfff331da2793f6e10d78f9d04b48e3366
|
7
|
+
data.tar.gz: 5bb2d70eea93254ece6a6c9ebf890f19bc19195c3836f44a5f5134412f319e0ad42ee4f62b1c4f374a5abc84e79526b7953c980d4fab63f374fcd7753e5db3b5
|
@@ -27,4 +27,18 @@ Feature: Enrich hashes
|
|
27
27
|
Then I should see the following "item name" enriched for each sub hash at "$.table.menu"
|
28
28
|
| value |
|
29
29
|
| Idly |
|
30
|
-
| Pongal |
|
30
|
+
| Pongal |
|
31
|
+
|
32
|
+
@array_of_hashes
|
33
|
+
Scenario: I should be able to enrich an array of hashes
|
34
|
+
Given I have the following keys setup in Redis
|
35
|
+
| key | value |
|
36
|
+
| items/1 | Idly |
|
37
|
+
| items/2 | Pongal |
|
38
|
+
| items/3 | Off Menu |
|
39
|
+
When I ask ArrayOfHash for menu
|
40
|
+
Then I should see the following "item name" in all the hashes
|
41
|
+
| value |
|
42
|
+
| Idly |
|
43
|
+
| Pongal |
|
44
|
+
| Off Menu |
|
@@ -1,4 +1,4 @@
|
|
1
|
-
When(/^I ask (DeepHash|Menu) for (metrics|menu)$/) do |lookup_service, method|
|
1
|
+
When(/^I ask (DeepHash|Menu|ArrayOfHash) for (metrics|menu)$/) do |lookup_service, method|
|
2
2
|
@enriched_hash = Object.const_get(lookup_service.classify).new.send(method)
|
3
3
|
end
|
4
4
|
|
@@ -11,4 +11,15 @@ end
|
|
11
11
|
|
12
12
|
Then(/^I should see the following "([^"]*)" enriched for each sub hash at "([^"]*)"$/) do |name, jsonpath, table|
|
13
13
|
expect(JsonPath.new(jsonpath).on(@enriched_hash.with_indifferent_access).first.collect { |i| i[name.parameterize.underscore.to_sym] }).to eq(table.hashes.collect { |i| i[:value] })
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
Then(/^I should see the following "([^"]*)" in all the hashes$/) do |name, table|
|
18
|
+
expected_names = table.hashes.collect { |row| row[:value] }
|
19
|
+
method_name = "#{name.parameterize.underscore.singularize}"
|
20
|
+
actual_names = @enriched_hash.collect do |elt|
|
21
|
+
elt.with_indifferent_access["#{method_name}"]
|
22
|
+
end
|
23
|
+
expect(actual_names).to eq(expected_names)
|
24
|
+
|
14
25
|
end
|
data/lib/looksist/hashed.rb
CHANGED
@@ -19,7 +19,7 @@ module Looksist
|
|
19
19
|
hash = send("#{after}_without_inject".to_sym, *args)
|
20
20
|
self.class.instance_variable_get(:@rules)[after].each do |opts|
|
21
21
|
if opts[:at].is_a? String
|
22
|
-
hash = update_using_json_path(hash, opts)
|
22
|
+
hash = update_using_json_path(hash, opts)
|
23
23
|
else
|
24
24
|
inject_attributes_at(hash[opts[:at]], opts)
|
25
25
|
end
|
@@ -50,12 +50,17 @@ module Looksist
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def update_using_json_path(hash, opts)
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
if hash.is_a?(Hash)
|
54
|
+
JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
|
55
|
+
i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless (i.nil? or i.empty?)
|
56
|
+
i
|
57
|
+
end.to_hash.deep_symbolize_keys
|
58
|
+
else
|
59
|
+
inject_attributes_for(hash, opts)
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
63
|
+
|
59
64
|
def inject_attributes_for(arry_of_hashes, opts)
|
60
65
|
entity_name = __entity__(opts[:bucket_name] || opts[:using])
|
61
66
|
keys = (arry_of_hashes.collect { |i| i[opts[:using]] }).compact.uniq
|
data/lib/looksist/version.rb
CHANGED
@@ -49,6 +49,7 @@ describe Looksist::Hashed do
|
|
49
49
|
})
|
50
50
|
end
|
51
51
|
|
52
|
+
|
52
53
|
it 'should be capable to deep lookup and inject from custom bucket' do
|
53
54
|
class CustomizedMenu
|
54
55
|
include Looksist
|
@@ -370,5 +371,37 @@ describe Looksist::Hashed do
|
|
370
371
|
}
|
371
372
|
}})
|
372
373
|
end
|
374
|
+
|
375
|
+
it 'should work for array of hashes' do
|
376
|
+
class ArrayOfHashes
|
377
|
+
include Looksist
|
378
|
+
|
379
|
+
def metrics
|
380
|
+
[
|
381
|
+
{
|
382
|
+
item_id: 1
|
383
|
+
},
|
384
|
+
{
|
385
|
+
item_id: 2
|
386
|
+
}
|
387
|
+
]
|
388
|
+
end
|
389
|
+
|
390
|
+
inject after: :metrics, at: '$', using: :item_id, populate: :item_name
|
391
|
+
end
|
392
|
+
|
393
|
+
expect(@mock).to receive(:mget).once.with(*%w(items/1 items/2)).and_return(%w(Idly Pongal))
|
394
|
+
|
395
|
+
expect(ArrayOfHashes.new.metrics).to eq(
|
396
|
+
[{
|
397
|
+
item_id: 1,
|
398
|
+
item_name: 'Idly'
|
399
|
+
},
|
400
|
+
{
|
401
|
+
item_id: 2,
|
402
|
+
item_name: 'Pongal'
|
403
|
+
}]
|
404
|
+
)
|
405
|
+
end
|
373
406
|
end
|
374
407
|
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RC
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- Rakefile
|
199
199
|
- features/bucket_lookup.feature
|
200
200
|
- features/hash_lookup.feature
|
201
|
+
- features/hash_services/array_of_hash.rb
|
201
202
|
- features/hash_services/deep_hash.rb
|
202
203
|
- features/hash_services/menu.rb
|
203
204
|
- features/model_lookup.feature
|
@@ -246,6 +247,7 @@ summary: Redis backed lookup for your models
|
|
246
247
|
test_files:
|
247
248
|
- features/bucket_lookup.feature
|
248
249
|
- features/hash_lookup.feature
|
250
|
+
- features/hash_services/array_of_hash.rb
|
249
251
|
- features/hash_services/deep_hash.rb
|
250
252
|
- features/hash_services/menu.rb
|
251
253
|
- features/model_lookup.feature
|