looksist 0.1.8 → 0.1.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: 59e638529e17d4968241ad31416d21e1a080b919
4
- data.tar.gz: ca701b1a666bb76129bc47b64ff88d5749827a77
3
+ metadata.gz: 0f92b64ae7a78e9d0f85c8e70e83196e3b4f4cd5
4
+ data.tar.gz: 96bf142e12546274d40d9c549655a6071adb7934
5
5
  SHA512:
6
- metadata.gz: 6ce8904095dce8cfe8c69d8fd13bd52969c3f9e055d4fa280f7f30a257c9ee31cffb6228c56c7c03ab98c3ca506e5f1ed0d66afeb7d53ec2ca62de42a3037960
7
- data.tar.gz: c0d847600a601f99569dac66439247882ded32f2df00a733e95e60147c6ae25f157bbbef386e0e41fc489e3951c3075fbabcee5217699f32be52cd8d1f051d62
6
+ metadata.gz: 9e4eff61111cc8a2eec151a698a2394b07bf2bac84a633432d29f1acb18f9da1e8fe6b0383cc35510b07ed4c87ab0a7149d70a651ee417c4f4f0c640104cc8ab
7
+ data.tar.gz: 7507c9604eea9f68e424a8d207aac06e3eeddd543ed733e2556314700ee2ed51820eb0c9e78495a3065a2e00e9784b3d9db53f4b376b709ed4213ff7be49b8b5
@@ -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|
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -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
- .and_return({name: 'Employee Name', location: 'Chennai'}.to_json)
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)
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC