hyper-resource 1.0.0.lap87 → 1.0.0.lap88
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: 9506b3bd2991d06242e006705fd6d591ba1b044bcd1df529b26f295a029d6b3d
|
4
|
+
data.tar.gz: 70e328ea0a95c3890e63144b1847c1500995aae931d7c50a1bf41957f73f620d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ac4b0885006ab61eefa49d93dd7e722d9c17554adb25f4809d5a1af77d64c71661a3dcd44e157498d8f009a9cd25ca294d310039820144e71d8e30076ab4e5a
|
7
|
+
data.tar.gz: 706c93b799aa2c50412f8e4c2a690c5e1f72341036f1616727b037a6a088f1795f2cb9f1dd0ee57e827b09784faf0a3a5c9669db4a471bd15b2a99ed2b5230ae
|
@@ -139,6 +139,7 @@ module HyperRecord
|
|
139
139
|
unless @rest_methods.has_key?(name)
|
140
140
|
@rest_methods[name] = options
|
141
141
|
@rest_methods[name] = { result: options[:default_result] }
|
142
|
+
@update_on_link[name] = {}
|
142
143
|
end
|
143
144
|
raise "#{self.class.to_s}[_no_id_].#{name}, can't execute instance collection_query_method without id!" unless self.id
|
144
145
|
self.class._promise_get_or_patch("#{resource_base_uri}/#{self.id}/methods/#{name}.json?timestamp=#{`Date.now() + Math.random()`}").then do |response_json|
|
@@ -160,6 +161,7 @@ module HyperRecord
|
|
160
161
|
unless @rest_methods.has_key?(name)
|
161
162
|
@rest_methods[name] = options
|
162
163
|
@rest_methods[name] = { result: options[:default_result] }
|
164
|
+
@update_on_link[name] = {}
|
163
165
|
end
|
164
166
|
unless @fetch_states.has_key?(name) && 'fi'.include?(@fetch_states[name])
|
165
167
|
self.send("promise_#{name}")
|
@@ -21,6 +21,7 @@ module HyperRecord
|
|
21
21
|
@state_key = "#{self.class.to_s}_#{self.object_id}"
|
22
22
|
@observers = Set.new
|
23
23
|
@registered_collections = Set.new
|
24
|
+
@update_on_link = {}
|
24
25
|
|
25
26
|
_initialize_from_hash(record_hash)
|
26
27
|
|
@@ -221,6 +222,12 @@ module HyperRecord
|
|
221
222
|
payload_hash = other_record.to_hash
|
222
223
|
self.class._promise_post("#{resource_base_uri}/#{self.id}/relations/#{relation_name}.json", { data: payload_hash }).then do |response|
|
223
224
|
other_record.instance_variable_get(:@properties).merge!(response.json[other_record.class.to_s.underscore])
|
225
|
+
@update_on_link.keys.each do |method|
|
226
|
+
@fetch_states[method] = 'u'
|
227
|
+
end
|
228
|
+
other_record.instance_variable_get(:@update_on_link).keys.each do |method|
|
229
|
+
other_record.instance_variable_get(:@fetch_states)[method] = 'u'
|
230
|
+
end
|
224
231
|
_notify_observers
|
225
232
|
other_record._notify_observers
|
226
233
|
self
|
@@ -275,6 +282,12 @@ module HyperRecord
|
|
275
282
|
raise "No relation for record of type #{other_record.class}" unless reflections.has_key?(relation_name)
|
276
283
|
@relations[relation_name].delete_if { |cr| cr == other_record } if !called_from_collection && @fetch_states[relation_name] == 'f'
|
277
284
|
self.class._promise_delete("#{resource_base_uri}/#{@properties[:id]}/relations/#{relation_name}.json?record_id=#{other_record.id}").then do |response|
|
285
|
+
@update_on_link.keys.each do |method|
|
286
|
+
@fetch_states[method] = 'u'
|
287
|
+
end
|
288
|
+
other_record.instance_variable_get(:@update_on_link).keys.each do |method|
|
289
|
+
other_record.instance_variable_get(:@fetch_states)[method] = 'u'
|
290
|
+
end
|
278
291
|
_notify_observers
|
279
292
|
other_record._notify_observers
|
280
293
|
self
|
@@ -339,6 +352,10 @@ module HyperRecord
|
|
339
352
|
if data[:cause][:destroyed]
|
340
353
|
c_record.instance_variable_set(:@remotely_destroyed, true)
|
341
354
|
c_record._local_destroy
|
355
|
+
else
|
356
|
+
c_record.instance_variable_get(:@update_on_link).keys.each do |method|
|
357
|
+
c_record.instance_variable_get(:@fetch_states)[method] = 'u'
|
358
|
+
end
|
342
359
|
end
|
343
360
|
if `Date.parse(#{c_record.updated_at}) >= Date.parse(#{data[:cause][:updated_at]})`
|
344
361
|
if @fetch_states[data[:relation]] == 'f'
|
@@ -350,9 +367,12 @@ module HyperRecord
|
|
350
367
|
end
|
351
368
|
end
|
352
369
|
@fetch_states[data[:relation]] = 'u'
|
353
|
-
|
370
|
+
@update_on_link.keys.each do |method|
|
371
|
+
@fetch_states[method] = 'u'
|
372
|
+
end
|
373
|
+
send("promise_#{data[:relation]}").then do |_collection|
|
354
374
|
_notify_observers
|
355
|
-
end.fail do |
|
375
|
+
end.fail do |_response|
|
356
376
|
error_message = "#{self}[#{self.id}].#{data[:relation]} failed to update!"
|
357
377
|
`console.error(error_message)`
|
358
378
|
end
|
@@ -365,9 +385,9 @@ module HyperRecord
|
|
365
385
|
_notify_observers
|
366
386
|
else
|
367
387
|
# rest_method without params
|
368
|
-
send("promise_#{data[:rest_method]}").then do |
|
388
|
+
send("promise_#{data[:rest_method]}").then do |_result|
|
369
389
|
_notify_observers
|
370
|
-
end.fail do |
|
390
|
+
end.fail do |_response|
|
371
391
|
error_message = "#{self}[#{self.id}].#{data[:rest_method]} failed to update!"
|
372
392
|
`console.error(error_message)`
|
373
393
|
end
|
@@ -384,10 +404,10 @@ module HyperRecord
|
|
384
404
|
return if `Date.parse(#{@properties[:updated_at]}) >= Date.parse(#{data[:updated_at]})`
|
385
405
|
end
|
386
406
|
self.class._class_fetch_states["record_#{id}"] = 'u'
|
387
|
-
self.class._promise_find(@properties[:id], self).then do |
|
407
|
+
self.class._promise_find(@properties[:id], self).then do |_record|
|
388
408
|
_notify_observers
|
389
409
|
self
|
390
|
-
end.fail do |
|
410
|
+
end.fail do |_response|
|
391
411
|
error_message = "#{self} failed to update!"
|
392
412
|
`console.error(error_message)`
|
393
413
|
end
|