hyper-resource 1.0.0.lap37 → 1.0.0.lap38
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7b649c6ec2096366f08fa25d95af57a01e869b764534bc1ae93b0d10fc60497
|
4
|
+
data.tar.gz: b09a6a3ce5354eaf2731b427cb6b5a45c4901007448d96974f5d0acfa97e8fbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d73031cd588bdb8b5e27976d947773316d69a3206053a4ce8a7a8187ab63f54eecaf55622eab3728ccd4b8ceb2dea916b7f9b082c95a6e8de4e3c30701c93a8
|
7
|
+
data.tar.gz: baace49e8182fbde221c2335dcdf56179237a8aa575630926d3a51c50c19822ae0d78edbe58419cbc0d7f9ee87d7b9a8df05f280827efef81cfa759352479a41
|
@@ -301,7 +301,7 @@ module HyperRecord
|
|
301
301
|
define_method(name) do |*args|
|
302
302
|
_register_observer
|
303
303
|
if self.id && (@rest_methods_hash[name][:force] || !@rest_methods_hash[name].has_key?(:result))
|
304
|
-
self.class.
|
304
|
+
self.class._promise_get_or_patch("#{resource_base_uri}/#{self.id}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}", *args).then do |result|
|
305
305
|
@rest_methods_hash[name][:result] = result # result is parsed json
|
306
306
|
_notify_observers
|
307
307
|
@rest_methods_hash[name][:result]
|
@@ -329,12 +329,12 @@ module HyperRecord
|
|
329
329
|
|
330
330
|
def scope(name, options)
|
331
331
|
scopes[name] = HyperRecord::Collection.new
|
332
|
-
define_singleton_method(name) do
|
332
|
+
define_singleton_method(name) do |*args|
|
333
333
|
if _class_fetch_states[name] == 'f'
|
334
334
|
scopes[name]
|
335
335
|
else
|
336
336
|
_register_class_observer
|
337
|
-
self.
|
337
|
+
self._promise_get_or_patch("#{resource_base_uri}/scopes/#{name}.json", *args).then do |response|
|
338
338
|
scopes[name] = _convert_array_to_collection(response.json[self.to_s.underscore][name])
|
339
339
|
_class_fetch_states[name] = 'f'
|
340
340
|
_notify_class_observers
|
@@ -408,6 +408,19 @@ module HyperRecord
|
|
408
408
|
Hyperloop::Resource::HTTP.get(uri, headers: { 'Content-Type' => 'application/json' })
|
409
409
|
end
|
410
410
|
|
411
|
+
def _promise_get_or_patch(uri, *args)
|
412
|
+
if args && args.size > 0
|
413
|
+
payload = { params: args }
|
414
|
+
_promise_patch(uri, payload).then do |result|
|
415
|
+
result.json[:result]
|
416
|
+
end
|
417
|
+
else
|
418
|
+
_promise_get(uri).then do |result|
|
419
|
+
result.json[:result]
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
411
424
|
def _promise_delete(uri)
|
412
425
|
Hyperloop::Resource::HTTP.delete(uri, headers: { 'Content-Type' => 'application/json' })
|
413
426
|
end
|
@@ -439,20 +452,6 @@ module HyperRecord
|
|
439
452
|
_class_observers << observer # @observers is a set, observers get added only once
|
440
453
|
end
|
441
454
|
end
|
442
|
-
|
443
|
-
def _rest_method_get_or_patch(name, id, *args)
|
444
|
-
uri = "#{resource_base_uri}/#{id}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}" # timestamp to invalidate browser caches
|
445
|
-
if args && args.size > 0
|
446
|
-
payload = { params: args }
|
447
|
-
_promise_patch(uri, payload).then do |result|
|
448
|
-
result.json[:result]
|
449
|
-
end
|
450
|
-
else
|
451
|
-
_promise_get(uri).then do |result|
|
452
|
-
result.json[:result]
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
455
|
end
|
457
456
|
|
458
457
|
end
|
@@ -17,8 +17,8 @@ class Hyperloop::Resource::ScopesController < ApplicationController
|
|
17
17
|
@record_class = guarded_record_class_from_param(mc_param)
|
18
18
|
@scope_name = params[:id].to_sym # :id is the scope name
|
19
19
|
@collection = nil
|
20
|
-
if @record_class && @record_class.scopes.has_key?(@scope_name)
|
21
|
-
@collection = @record_class.send(@scope_name)
|
20
|
+
if @record_class && @record_class.scopes.has_key?(@scope_name) # guard
|
21
|
+
@collection = @record_class.send(@scope_name)
|
22
22
|
end
|
23
23
|
respond_to do |format|
|
24
24
|
if @record_class && @collection
|
@@ -29,8 +29,26 @@ class Hyperloop::Resource::ScopesController < ApplicationController
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def update
|
33
|
+
mc_param = record_class_param
|
34
|
+
mc_param = mc_param.chop if mc_param.end_with?('s')
|
35
|
+
@model_klass = guarded_record_class_from_param(mc_param)
|
36
|
+
@scope_name = params[:id].to_sym # :id is the scope name
|
37
|
+
@collection = nil
|
38
|
+
if @model_klass && @model_klass.scopes.has_key?(@scope_name) # guard
|
39
|
+
@collection = @model_klass.send(@scope_name, params[:params])
|
40
|
+
end
|
41
|
+
respond_to do |format|
|
42
|
+
if @model_klass && @collection
|
43
|
+
format.json
|
44
|
+
else
|
45
|
+
format.json { render json: {}, status: :unprocessable_entity }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
32
50
|
private
|
33
|
-
|
51
|
+
|
34
52
|
def record_class_param
|
35
53
|
params.require(:record_class)
|
36
54
|
end
|