looksist 0.2.7 → 0.2.8

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: 0994ca184629691fa505977431489e2e9666d513
4
- data.tar.gz: a0f43956fe8b0569520f56a3da0e8b6ece73e636
3
+ metadata.gz: af0970edfde1eaaedf7ff9dfeb7618e1c815beb9
4
+ data.tar.gz: 6a05e43560a57b6cbc150bb59b149f02316fd923
5
5
  SHA512:
6
- metadata.gz: 5c2877f5c569d667a54a36be62a97e62fd5c9ccd765e7ac3f340dd5011d71dfe68b951793799428e7677a6c1d738e028c2bed581e976d1054cca6898ae0cf1b2
7
- data.tar.gz: 38c95f0ca67deba2942b8b5ae3e0bdf9b90727a60cb189b78dd89fa265a93bc689234f68285a0fc276363c4ab94b63ebbffe426b64f9ef8d3caa5b76644703af
6
+ metadata.gz: 5ce3783053136540929bc910c84b51c6e0fa00f0aa448e2fc1b88449863096f3cba725e43e58b9ee804600dd59c2ab11b653d8757431ffe84b396c799ab35573
7
+ data.tar.gz: feb2a4bb3cb516f7b34d95c4d474011fb5636cceae2fa32013948b0e72a3c764200cf1bd69a52fc3752c9be86448835086cd344dfd0a0d85fb5e36e39a52dc34
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - ruby-2.1.1
3
4
  - ruby-2.1.2
5
+ - ruby-2.1.3
6
+ - ruby-1.9.3
4
7
  - jruby-1.7.16
5
8
  services:
6
9
  - redis-server
data/README.md CHANGED
@@ -15,14 +15,17 @@ Add this line to your application's Gemfile:
15
15
 
16
16
  gem 'looksist'
17
17
 
18
- And then execute:
19
-
20
- $ bundle
21
-
22
- Or install it yourself as:
23
-
24
- $ gem install looksist
25
-
18
+ ## Supported Ruby Versions
19
+
20
+ ruby 2.1
21
+ ruby 1.9.3
22
+ jruby 1.7
23
+
24
+ ## Dependencies
25
+
26
+ JsonPath - required by the gem.
27
+ ActiveSupport - external dependency, make sure to require it in your project.
28
+
26
29
  ## Usage
27
30
 
28
31
  ### With Object Models (Her, Active Resource or any of your choice)
data/lib/looksist/core.rb CHANGED
@@ -59,7 +59,7 @@ module Looksist
59
59
  lookup_attributes ||= {}
60
60
  other_attributes = lookup_attributes.keys.each_with_object({}) do |a, acc|
61
61
  using = lookup_attributes[a]
62
- acc[a] = obj.send(a) if obj.respond_to?(using)
62
+ acc[a] = obj.send(a) if obj.attributes.has_key?(using.to_s)
63
63
  end
64
64
  obj.attributes.merge(other_attributes)
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -41,23 +41,17 @@ describe Looksist do
41
41
  include Her::Model
42
42
  use_api TEST_API
43
43
  include Looksist
44
- attr_accessor :id
45
44
  lookup [:name, :age], using: :id, as: {name: 'nome'}
46
-
47
- def initialize(id)
48
- @id = id
49
- end
50
-
51
45
  def as_json(opts)
52
- super(opts).merge(id: @id)
46
+ super(opts).merge(attributes)
53
47
  end
54
48
  end
55
49
  end
56
50
  expect(@mock).to receive(:get).exactly(4).times.with('ids/1').and_return({name: 'Rajini', age: 16}.to_json)
57
- e = AliasSpecificLookup::NoCacheEmployee.new(1)
51
+ e = AliasSpecificLookup::NoCacheEmployee.new(id:1)
58
52
  expect(e.nome).to eq('Rajini')
59
53
  expect(e.age).to eq(16)
60
- expect(e.to_json).to eq("{\"nome\":\"Rajini\",\"age\":16,\"id\":1}")
54
+ expect(e.to_json).to eq("{\"id\":1,\"nome\":\"Rajini\",\"age\":16}")
61
55
  end
62
56
  end
63
57
 
@@ -69,17 +63,10 @@ describe Looksist do
69
63
  include Her::Model
70
64
  use_api TEST_API
71
65
  include Looksist
72
- attr_accessor :id
73
- attr_accessor :department_id
74
66
  lookup :name, using: :id, bucket_name: 'employees'
75
67
 
76
- def initialize(id, department_id)
77
- @id = id
78
- @department_id = department_id
79
- end
80
-
81
68
  def as_json(opts)
82
- super(opts).merge(id: @id)
69
+ super(opts).merge(attributes)
83
70
  end
84
71
  end
85
72
 
@@ -99,9 +86,9 @@ describe Looksist do
99
86
  expect(@mock).to receive(:get).once.with('employees/1').and_return('SuperStar')
100
87
  expect(@mock).to receive(:get).once.with('departments/2').and_return('Kollywood')
101
88
 
102
- e = InheritedLookUp::Manager.new(1, 2)
89
+ e = InheritedLookUp::Manager.new(id:1, department_id:2)
103
90
 
104
- expect(e.to_json).to eq("{\"department_name\":\"Kollywood\",\"name\":\"SuperStar\",\"id\":1,\"is_manager\":true}")
91
+ expect(e.to_json).to eq("{\"department_id\":2,\"id\":1,\"department_name\":\"Kollywood\",\"name\":\"SuperStar\",\"is_manager\":true}")
105
92
  end
106
93
  end
107
94
 
@@ -164,17 +151,20 @@ describe Looksist do
164
151
  include Her::Model
165
152
  use_api TEST_API
166
153
  include Looksist
167
-
168
- lookup :name, using: :employee_id
154
+ lookup :name, using: :id, bucket_name: 'employees'
169
155
 
170
156
  def as_json(opts)
171
157
  super(opts)
172
158
  end
159
+
173
160
  end
174
161
  end
175
- expect(@mock).to receive(:get).never.with('employees/1')
176
- e = TolerantLookUp::Employee.new
177
- expect(e.to_json).to eq('{}')
162
+ expect(@mock).to receive(:get).once.with('employees/1').and_return('RajiniKanth')
163
+ expect(@mock).to receive(:get).never.with('employees/')
164
+ e1 = TolerantLookUp::Employee.new(id:1)
165
+ e2 = TolerantLookUp::Employee.new
166
+ expect(e1.to_json).to eq("{\"id\":1,\"name\":\"RajiniKanth\"}")
167
+ expect(e2.to_json).to eq('{}')
178
168
  end
179
169
  end
180
170
 
@@ -185,22 +175,17 @@ describe Looksist do
185
175
  include Her::Model
186
176
  use_api TEST_API
187
177
  include Looksist
188
- attr_accessor :id
189
178
  lookup :name, using: :id, bucket_name: 'employees', as: {name: 'nome'}
190
179
 
191
- def initialize(id)
192
- @id = id
193
- end
194
-
195
180
  def as_json(opts)
196
- super(opts).merge(id: @id)
181
+ super(opts).merge(attributes)
197
182
  end
198
183
  end
199
184
  end
200
185
  expect(@mock).to receive(:get).once.with('employees/1').and_return('Rajini')
201
- e = AliasLookup::Employee.new(1)
186
+ e = AliasLookup::Employee.new(id: 1)
202
187
  expect(e.nome).to eq('Rajini')
203
- expect(e.to_json).to eq("{\"nome\":\"Rajini\",\"id\":1}")
188
+ expect(e.to_json).to eq("{\"id\":1,\"nome\":\"Rajini\"}")
204
189
  end
205
190
 
206
191
  it 'should fetch attributes and use the alias for specific attributes in the api' do
@@ -209,23 +194,18 @@ describe Looksist do
209
194
  include Her::Model
210
195
  use_api TEST_API
211
196
  include Looksist
212
- attr_accessor :id
213
197
  lookup [:name, :age], using: :id, as: {name: 'nome'}
214
198
 
215
- def initialize(id)
216
- @id = id
217
- end
218
-
219
199
  def as_json(opts)
220
- super(opts).merge(id: @id)
200
+ super(opts).merge(attributes)
221
201
  end
222
202
  end
223
203
  end
224
204
  expect(@mock).to receive(:get).once.with('ids/1').and_return({name: 'Rajini', age: 16}.to_json)
225
- e = AliasSpecificLookup::Employee.new(1)
205
+ e = AliasSpecificLookup::Employee.new(id: 1)
226
206
  expect(e.nome).to eq('Rajini')
227
207
  expect(e.age).to eq(16)
228
- expect(e.to_json).to eq("{\"nome\":\"Rajini\",\"age\":16,\"id\":1}")
208
+ expect(e.to_json).to eq("{\"id\":1,\"nome\":\"Rajini\",\"age\":16}")
229
209
  end
230
210
  end
231
211
 
@@ -290,7 +270,6 @@ describe Looksist do
290
270
  lookup [:name, :location], using: :id
291
271
  lookup [:age, :sex], using: :employee_id
292
272
  lookup [:pager, :cell], using: :contact_id
293
-
294
273
  def initialize(id)
295
274
  @contact_id = @id = @employee_id = id
296
275
  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.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC