looksist 0.1.8 → 0.1.9
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 +4 -4
- data/lib/looksist/hashed.rb +2 -2
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +38 -0
- data/spec/looksist/looksist_spec.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f92b64ae7a78e9d0f85c8e70e83196e3b4f4cd5
|
4
|
+
data.tar.gz: 96bf142e12546274d40d9c549655a6071adb7934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e4eff61111cc8a2eec151a698a2394b07bf2bac84a633432d29f1acb18f9da1e8fe6b0383cc35510b07ed4c87ab0a7149d70a651ee417c4f4f0c640104cc8ab
|
7
|
+
data.tar.gz: 7507c9604eea9f68e424a8d207aac06e3eeddd543ed733e2556314700ee2ed51820eb0c9e78495a3065a2e00e9784b3d9db53f4b376b709ed4213ff7be49b8b5
|
data/lib/looksist/hashed.rb
CHANGED
@@ -44,14 +44,14 @@ module Looksist
|
|
44
44
|
def inject_attributes_at(hash_offset, opts)
|
45
45
|
return hash_offset if hash_offset.nil? or hash_offset.empty?
|
46
46
|
keys = hash_offset[opts[:using]]
|
47
|
-
entity_name = __entity__(opts[:using])
|
47
|
+
entity_name = __entity__(opts[:bucket_name] || opts[:using])
|
48
48
|
values = Looksist.redis_service.send("#{entity_name}_for", keys)
|
49
49
|
hash_offset[opts[:populate]] = values
|
50
50
|
hash_offset
|
51
51
|
end
|
52
52
|
|
53
53
|
def inject_attributes_for(arry_of_hashes, opts)
|
54
|
-
entity_name = __entity__(opts[:using])
|
54
|
+
entity_name = __entity__(opts[:bucket_name] || opts[:using])
|
55
55
|
keys = (arry_of_hashes.collect { |i| i[opts[:using]] }).compact.uniq
|
56
56
|
values = keys.zip(Looksist.redis_service.send("#{entity_name}_for", keys)).to_h
|
57
57
|
arry_of_hashes.each do |elt|
|
data/lib/looksist/version.rb
CHANGED
@@ -49,6 +49,44 @@ describe Looksist::Hashed do
|
|
49
49
|
})
|
50
50
|
end
|
51
51
|
|
52
|
+
it 'should be capable to deep lookup and inject from custom bucket' do
|
53
|
+
class CustomizedMenu
|
54
|
+
include Looksist
|
55
|
+
|
56
|
+
def metrics
|
57
|
+
{
|
58
|
+
table: {
|
59
|
+
menu: [
|
60
|
+
{
|
61
|
+
item_id: 1
|
62
|
+
},
|
63
|
+
{
|
64
|
+
item_id: 2
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
inject after: :metrics, at: '$.table.menu', using: :item_id, populate: :item_name, bucket_name: 'menu_items'
|
72
|
+
end
|
73
|
+
|
74
|
+
expect(@mock).to receive(:mget).once.with(*%w(menu_items/1 menu_items/2)).and_return(%w(Idly Pongal))
|
75
|
+
|
76
|
+
expect(CustomizedMenu.new.metrics).to eq({
|
77
|
+
table: {
|
78
|
+
menu: [{
|
79
|
+
item_id: 1,
|
80
|
+
item_name: 'Idly'
|
81
|
+
},
|
82
|
+
{
|
83
|
+
item_id: 2,
|
84
|
+
item_name: 'Pongal'
|
85
|
+
}]
|
86
|
+
}
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
52
90
|
xit 'should be capable to deep lookup and inject - another example' do
|
53
91
|
class NewMenu
|
54
92
|
include Looksist
|
@@ -53,6 +53,17 @@ describe Looksist do
|
|
53
53
|
|
54
54
|
context 'Lazy Evaluation' do
|
55
55
|
module LazyEval
|
56
|
+
class HerEmployee
|
57
|
+
include Her::Model
|
58
|
+
use_api TEST_API
|
59
|
+
include Looksist
|
60
|
+
|
61
|
+
lookup :name, using = :employee_id
|
62
|
+
|
63
|
+
def as_json(opts)
|
64
|
+
super(opts).merge(another_attr: 'Hello World')
|
65
|
+
end
|
66
|
+
end
|
56
67
|
class Employee
|
57
68
|
include Looksist
|
58
69
|
attr_accessor :id
|
@@ -66,6 +77,7 @@ describe Looksist do
|
|
66
77
|
it 'should not eager evaluate' do
|
67
78
|
expect(@mock).to_not receive(:get)
|
68
79
|
LazyEval::Employee.new(1)
|
80
|
+
LazyEval::HerEmployee.new(employee_id: 1)
|
69
81
|
end
|
70
82
|
end
|
71
83
|
|
@@ -137,7 +149,7 @@ describe Looksist do
|
|
137
149
|
it 'should share storage between instances to improve performance' do
|
138
150
|
employee_first_instance = Employee.new(1)
|
139
151
|
expect(@mock).to receive(:get).once.with('ids/1')
|
140
|
-
|
152
|
+
.and_return({name: 'Employee Name', location: 'Chennai'}.to_json)
|
141
153
|
employee_first_instance.name
|
142
154
|
|
143
155
|
employee_second_instance = Employee.new(1)
|