logical_model 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjA1ZjcxZGY0MmRhYzYyOTMyOTFjMzk3MzkwNjA0YzUyZDAzMjIzYg==
5
- data.tar.gz: !binary |-
6
- ZmYwMTE4NWE0ODA1MGEyZGY0NWIyZjY1NjQ4OTQ2MTNhNWFmNGVhMw==
2
+ SHA1:
3
+ metadata.gz: 1a55e6cf668634d84d93d2a35ca533cafcff6928
4
+ data.tar.gz: 5fe412688d5d6e8b975ed5fcc550fea858bdbcb4
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZTI3MWU0YTc0M2FjYWM1ZTk5ZWVmN2U3YmRkNTM3N2NhM2JlYTExOTBmYTE5
10
- ZTkzM2E4MThhOWVhNDJkZjU2MTA4MzIwNDgyYmMzODhlZjQwOGYzNDJiOWFh
11
- ZDk3NWY2YjY5ZjU1ZmE4MzI5NzkxNTc5YmYzYzE4ZWU2MDJhYzQ=
12
- data.tar.gz: !binary |-
13
- ZTI4NDZhODVlNDIyMTdmMGQ0ODIwOTEwMmM3YjY0MTcwNTczNDQxZTZmM2Rj
14
- N2I4Zjk2NTJlOGFlZGM3YmJkODk3MmRkZTc1MzNmNWEyN2M5MWE4MzU2NDcw
15
- ZGYzYjZjNzM1M2VkOTRiMWVmZTI5Y2MwNWI4YjU1ZDEzNTE1YjQ=
6
+ metadata.gz: d33cfee597475576d902975556036c759ee06fa7134353c48094e4e0944c19282cbfc70dd580699a099958041272625b8c740449a4e169aff076b44ac8ab4fbd
7
+ data.tar.gz: 6ebe4b1da56e042db51c2347845af92da15bb459dc97aab8725942d2f612d209765e61ffb0de39c5d58b6b297fb9ea9a53ac84ea40cc443094596360e73c86d1
data/lib/logical_model.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'timeout'
2
1
  require 'active_model'
3
2
  require 'typhoeus'
4
3
  require 'active_support/all' # todo migrate to yajl
@@ -57,10 +57,7 @@ class LogicalModel
57
57
  params = { self.json_root => self.attributes }.merge(params)
58
58
  params = self.class.merge_key(params)
59
59
 
60
- response = nil
61
- Timeout::timeout(self.class.timeout/1000) do
62
- response = Typhoeus::Request.post( self.class.resource_uri, :body => params, :timeout => self.class.timeout )
63
- end
60
+ response = Typhoeus::Request.post( self.class.resource_uri, body: params, timeout: self.class.timeout )
64
61
  self.last_response_code = response.code
65
62
  if response.code == 201 || response.code == 202
66
63
  log_ok(response)
@@ -80,9 +77,6 @@ class LogicalModel
80
77
  log_failed(response)
81
78
  return nil
82
79
  end
83
- rescue Timeout::Error
84
- self.class.logger.warn "timeout"
85
- return nil
86
80
  end
87
81
 
88
82
  # Updates Objects attributes, this will only send attributes passed as arguments
@@ -102,12 +96,9 @@ class LogicalModel
102
96
 
103
97
  params = self.class.merge_key(params)
104
98
 
105
- response = nil
106
- Timeout::timeout(self.class.timeout/1000) do
107
- response = Typhoeus::Request.put( self.class.resource_uri(id),
108
- :params => params,
109
- :timeout => self.class.timeout )
110
- end
99
+ response = Typhoeus::Request.put( self.class.resource_uri(id),
100
+ params: params,
101
+ timeout: self.class.timeout )
111
102
 
112
103
  if response.code == 200
113
104
  log_ok(response)
@@ -116,10 +107,6 @@ class LogicalModel
116
107
  log_failed(response)
117
108
  return nil
118
109
  end
119
-
120
- rescue Timeout::Error
121
- self.class.logger.warn("request timed out")
122
- return nil
123
110
  end
124
111
 
125
112
  # Saves Objects attributes
@@ -141,10 +128,7 @@ class LogicalModel
141
128
 
142
129
  params = { self.json_root => sending_params }
143
130
  params = self.class.merge_key(params)
144
- response = nil
145
- Timeout::timeout(self.class.timeout/1000) do
146
- response = Typhoeus::Request.put( self.class.resource_uri(id), :params => params, :timeout => self.class.timeout )
147
- end
131
+ response = Typhoeus::Request.put( self.class.resource_uri(id), params: params, timeout: self.class.timeout )
148
132
  if response.code == 200
149
133
  log_ok(response)
150
134
  return self
@@ -152,9 +136,6 @@ class LogicalModel
152
136
  log_failed(response)
153
137
  return nil
154
138
  end
155
- rescue Timeout::Error
156
- self.class.logger.warn "timeout"
157
- return nil
158
139
  end
159
140
 
160
141
  # Destroy object
@@ -216,13 +197,8 @@ class LogicalModel
216
197
  self.retries.times do
217
198
  begin
218
199
  async_all(options){|i| result = i}
219
- Timeout::timeout(self.timeout/1000) do
220
- self.hydra.run
221
- end
200
+ self.hydra.run
222
201
  break unless result.nil?
223
- rescue Timeout::Error
224
- self.logger.warn("timeout")
225
- result = nil
226
202
  end
227
203
  end
228
204
  result
@@ -277,13 +253,8 @@ class LogicalModel
277
253
  self.retries.times do
278
254
  begin
279
255
  async_paginate(options){|i| result = i}
280
- Timeout::timeout(self.timeout/1000) do
281
- self.hydra.run
282
- end
256
+ self.hydra.run
283
257
  break unless result.nil?
284
- rescue Timeout::Error
285
- self.logger.warn("timeout")
286
- result = nil
287
258
  end
288
259
  end
289
260
  result
@@ -326,13 +297,8 @@ class LogicalModel
326
297
  def count(options={})
327
298
  result = nil
328
299
  async_count(options){|i| result = i}
329
- Timeout::timeout(self.timeout/1000) do
330
- self.hydra.run
331
- end
300
+ self.hydra.run
332
301
  result
333
- rescue Timeout::Error
334
- self.logger.warn("timeout")
335
- return nil
336
302
  end
337
303
 
338
304
  # Asynchronic Find
@@ -352,9 +318,10 @@ class LogicalModel
352
318
  request.on_complete do |response|
353
319
  if response.code >= 200 && response.code < 400
354
320
  log_ok(response)
355
- yield async_find_response(id, params, response.body)
321
+ yield async_find_response(id, params, response.body), response.code
356
322
  else
357
323
  log_failed(response)
324
+ yield nil, response.code
358
325
  end
359
326
  end
360
327
 
@@ -362,20 +329,30 @@ class LogicalModel
362
329
  end
363
330
 
364
331
  def async_find_response(id, params, body)
365
- self.new.from_json(body) # this from_json is defined in ActiveModel::Serializers::JSON
332
+ if body.blank?
333
+ # if request failed failed unexpectedly we may get code 200 but empty body
334
+ self.logger.warn("got response code 200 but empty body")
335
+ return nil
336
+ end
337
+
338
+ self.new.from_json(body)
366
339
  end
367
340
 
368
341
  # synchronic find
369
342
  def find(id, params = {})
370
343
  result = nil
371
- async_find(id, params){|i| result = i}
372
- Timeout::timeout(self.timeout/1000) do
373
- self.hydra.run
344
+ self.retries.times do
345
+ begin
346
+ response_code = nil
347
+ async_find(id, params) do |res,code|
348
+ result = res
349
+ response_code = code
350
+ end
351
+ self.hydra.run
352
+ break unless result.nil? && (response_code != 404) # don't retry if response was 404
353
+ end
374
354
  end
375
355
  result
376
- rescue Timeout::Error
377
- self.logger.warn("timeout")
378
- return nil
379
356
  end
380
357
 
381
358
  # Deletes Object#id
@@ -391,13 +368,10 @@ class LogicalModel
391
368
 
392
369
  params = self.merge_key(params)
393
370
 
394
- response = nil
395
- Timeout::timeout(self.timeout/1000) do
396
- response = Typhoeus::Request.delete( self.resource_uri(id),
397
- :params => params,
398
- :timeout => self.timeout
399
- )
400
- end
371
+ response = Typhoeus::Request.delete( self.resource_uri(id),
372
+ params: params,
373
+ timeout: self.timeout
374
+ )
401
375
  if response.code == 200
402
376
  log_ok(response)
403
377
  return self
@@ -405,9 +379,6 @@ class LogicalModel
405
379
  log_failed(response)
406
380
  return nil
407
381
  end
408
- rescue Timeout::Error
409
- self.logger.warn "timeout"
410
- return nil
411
382
  end
412
383
 
413
384
  # Deletes all Objects matching given ids
@@ -427,13 +398,10 @@ class LogicalModel
427
398
  params = self.merge_key(params)
428
399
  params = params.merge({:ids => ids})
429
400
 
430
- response = nil
431
- Timeout::timeout(self.timeout/1000) do
432
- response = Typhoeus::Request.delete( self.resource_uri+"/destroy_multiple",
433
- :params => params,
434
- :timeout => self.timeout
435
- )
436
- end
401
+ response = Typhoeus::Request.delete( self.resource_uri+"/destroy_multiple",
402
+ params: params,
403
+ timeout: self.timeout
404
+ )
437
405
  if response.code == 200
438
406
  log_ok(response)
439
407
  return self
@@ -441,9 +409,6 @@ class LogicalModel
441
409
  log_failed(response)
442
410
  return nil
443
411
  end
444
- rescue Timeout::Error
445
- self.logger.warn "timeout"
446
- return nil
447
412
  end
448
413
  end
449
414
  end
@@ -465,4 +430,4 @@ class LogicalModel
465
430
  end
466
431
  end
467
432
 
468
- end
433
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "logical_model"
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dwayne Macgowan"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logical_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dwayne Macgowan
@@ -14,28 +14,28 @@ dependencies:
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -70,224 +70,224 @@ dependencies:
70
70
  name: kaminari
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.13.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.13.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: debugger
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: activerecord
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: shoulda
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: bundler
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: 1.2.2
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.2.2
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: jeweler
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: 1.6.4
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 1.6.4
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rcov
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: sqlite3-ruby
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ! '>='
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ! '>='
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: sinatra
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ~>
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
201
  version: 1.2.6
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ~>
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: 1.2.6
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: json
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ! '>='
213
+ - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ! '>='
220
+ - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: gemcutter
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - ! '>='
227
+ - - ">="
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ! '>='
234
+ - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: rspec-rails
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
- - - ! '>='
241
+ - - ">="
242
242
  - !ruby/object:Gem::Version
243
243
  version: '0'
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - ! '>='
248
+ - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  - !ruby/object:Gem::Dependency
252
252
  name: guard-rspec
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - ! '>='
255
+ - - ">="
256
256
  - !ruby/object:Gem::Version
257
257
  version: '0'
258
258
  type: :development
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - ! '>='
262
+ - - ">="
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: rb-inotify
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
- - - ! '>='
269
+ - - ">="
270
270
  - !ruby/object:Gem::Version
271
271
  version: '0'
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - ! '>='
276
+ - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: libnotify
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - ! '>='
283
+ - - ">="
284
284
  - !ruby/object:Gem::Version
285
285
  version: '0'
286
286
  type: :development
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
- - - ! '>='
290
+ - - ">="
291
291
  - !ruby/object:Gem::Version
292
292
  version: '0'
293
293
  description: LogicalModel allows to use a resource as a model. It is based on web
@@ -299,8 +299,8 @@ extra_rdoc_files:
299
299
  - LICENSE.txt
300
300
  - README.rdoc
301
301
  files:
302
- - .document
303
- - .travis.yml
302
+ - ".document"
303
+ - ".travis.yml"
304
304
  - Gemfile
305
305
  - Gemfile.lock
306
306
  - Guardfile
@@ -347,12 +347,12 @@ require_paths:
347
347
  - lib
348
348
  required_ruby_version: !ruby/object:Gem::Requirement
349
349
  requirements:
350
- - - ! '>='
350
+ - - ">="
351
351
  - !ruby/object:Gem::Version
352
352
  version: '0'
353
353
  required_rubygems_version: !ruby/object:Gem::Requirement
354
354
  requirements:
355
- - - ! '>='
355
+ - - ">="
356
356
  - !ruby/object:Gem::Version
357
357
  version: '0'
358
358
  requirements: []
@@ -362,4 +362,3 @@ signing_key:
362
362
  specification_version: 3
363
363
  summary: LogicalModel allows to use a resource as a model.
364
364
  test_files: []
365
- has_rdoc: