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: d97e990da393fe7171a941e1a983f90864bb873314cf51fa1160cb40b7c89e30
4
- data.tar.gz: 76a994108050b12d21474d4aeb43e49ad5343bed5fe0bcf7df14c2da3b1a1a24
3
+ metadata.gz: d7b649c6ec2096366f08fa25d95af57a01e869b764534bc1ae93b0d10fc60497
4
+ data.tar.gz: b09a6a3ce5354eaf2731b427cb6b5a45c4901007448d96974f5d0acfa97e8fbd
5
5
  SHA512:
6
- metadata.gz: 10cbff697773ae684420356beba06168db1e9e843d36acacb070cb8b4df194e5333479da7cb4d0aa8ef57676a485edbea7e003af303b49db102dbbcd73e8e1fa
7
- data.tar.gz: 00fa3cefc9e6b59fc5d94948484d2e11b4e12177051f23d27ee72ba98e54e8007e90fa1eaff0a21afd00643bab75f6e120a3e0b5ec79c4a1fcebd3512a8c91c3
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._rest_method_get_or_patch(name, self.id, *args).then do |result|
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._promise_get("#{resource_base_uri}/scopes/#{name}.json").then do |response|
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) # guard
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
@@ -1,5 +1,5 @@
1
1
  module Hyperloop
2
2
  module Resource
3
- VERSION = '1.0.0.lap37'
3
+ VERSION = '1.0.0.lap38'
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.lap37
4
+ version: 1.0.0.lap38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann