hyper-resource 1.0.0.lap50 → 1.0.0.lap51

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
  SHA256:
3
- metadata.gz: 1bf46013acaf00398255c2396db9e004a6ac45404be32e1f7df15b60827e52a0
4
- data.tar.gz: 9c7e8393a77636f2d6342682f2c1691b3a5239432e3e5045d6c7b4a441fa30ce
3
+ metadata.gz: 166d7738a8242d4a8a7fd15a48c97afe4e76d1378349414797e3903228dd3e65
4
+ data.tar.gz: 5ef6c17b6754100a4981a1483c190077754563c857aa38473612a8684904c36b
5
5
  SHA512:
6
- metadata.gz: ffe0b0a8d4be359eb2eedc67a652530c632857a8b141e275e1819e4f66144c449a3149bca49764a6f40ff8bc5544703c4fd4ed0fe5a43b6a0e8216e7f3087396
7
- data.tar.gz: 64fd5dc93d13cd73850feac016c78a3e3c50665f5b7ef66a332a9d51132207d4cd6761b8bd4c2a54514d2d1043b5f2d9a933621d975905bbb0b044f4ccc1d127
6
+ metadata.gz: 8ec68eb7cda9c4a194bd960ec1d1e1b056864c062a874405883dae1773aa3f9699751eba8bef2fcd4f141a2b77c77f25c6bd4c96684dfaa8f33dafd1cea4430e
7
+ data.tar.gz: 93aa6d5fbb63da6eae65f93d07942abbd59dea6f685ed26a87e5de3be74cfd42a38c15cc5de150c9ab9c7bfe2718ebeba335780c6fa2dd242987fdf2ebc23914
@@ -308,18 +308,21 @@ module HyperRecord
308
308
  def rest_class_method(name, options = { default_result: '...' })
309
309
  rest_methods[name] = options
310
310
  rest_methods[name][:class_method] = true
311
+ singleton_class.send(:define_method, "promise_#{name}") do |*args|
312
+ _promise_get_or_patch("#{resource_base_uri}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}", *args).then do |response_json|
313
+ rest_methods[name][:result] = response_json[:result] # result is parsed json
314
+ _notify_class_observers
315
+ rest_methods[name][:result]
316
+ end.fail do |response|
317
+ error_message = "#{self.to_s}.#{name}, a rest_method, failed to fetch records!"
318
+ `console.error(error_message)`
319
+ response
320
+ end
321
+ end
311
322
  singleton_class.send(:define_method, name) do |*args|
312
323
  _register_class_observer
313
324
  if rest_methods[name][:force] || !rest_methods[name].has_key?(:result)
314
- _promise_get_or_patch("#{resource_base_uri}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}", *args).then do |response_json|
315
- rest_methods[name][:result] = response_json[:result] # result is parsed json
316
- _notify_class_observers
317
- rest_methods[name][:result]
318
- end.fail do |response|
319
- error_message = "#{self.to_s}.#{name}, a rest_method, failed to fetch records!"
320
- `console.error(error_message)`
321
- response
322
- end
325
+ self.send("promise_#{name}", *args)
323
326
  end
324
327
  if rest_methods[name].has_key?(:result)
325
328
  rest_methods[name][:result]
@@ -339,18 +342,21 @@ module HyperRecord
339
342
 
340
343
  def rest_method(name, options = { default_result: '...' })
341
344
  rest_methods[name] = options
345
+ define_method("promise_#{name}") do |*args|
346
+ self.class._promise_get_or_patch("#{resource_base_uri}/#{self.id}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}", *args).then do |response_json|
347
+ @rest_methods_hash[name][:result] = response_json[:result] # result is parsed json
348
+ _notify_observers
349
+ @rest_methods_hash[name][:result]
350
+ end.fail do |response|
351
+ error_message = "#{self.class.to_s}[#{self.id}].#{name}, a rest_method, failed to fetch records!"
352
+ `console.error(error_message)`
353
+ response
354
+ end
355
+ end
342
356
  define_method(name) do |*args|
343
357
  _register_observer
344
358
  if self.id && (@rest_methods_hash[name][:force] || !@rest_methods_hash[name].has_key?(:result))
345
- self.class._promise_get_or_patch("#{resource_base_uri}/#{self.id}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}", *args).then do |response_json|
346
- @rest_methods_hash[name][:result] = response_json[:result] # result is parsed json
347
- _notify_observers
348
- @rest_methods_hash[name][:result]
349
- end.fail do |response|
350
- error_message = "#{self.class.to_s}[#{self.id}].#{name}, a rest_method, failed to fetch records!"
351
- `console.error(error_message)`
352
- response
353
- end
359
+ self.send("promise_#{name}", *args)
354
360
  end
355
361
  if @rest_methods_hash[name].has_key?(:result)
356
362
  @rest_methods_hash[name][:result]
@@ -1,5 +1,5 @@
1
1
  module Hyperloop
2
2
  module Resource
3
- VERSION = '1.0.0.lap50'
3
+ VERSION = '1.0.0.lap51'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.lap50
4
+ version: 1.0.0.lap51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann