hyper-resource 1.0.0.lap50 → 1.0.0.lap51
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/hyper_record/class_methods.rb +24 -18
- data/lib/hyperloop/resource/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 166d7738a8242d4a8a7fd15a48c97afe4e76d1378349414797e3903228dd3e65
|
|
4
|
+
data.tar.gz: 5ef6c17b6754100a4981a1483c190077754563c857aa38473612a8684904c36b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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.
|
|
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]
|