reactive-record 0.7.26 → 0.7.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactive_record/active_record/reactive_record/base.rb +8 -6
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +55 -40
- data/lib/reactive_record/active_record/reactive_record/while_loading.rb +2 -0
- data/lib/reactive_record/server_data_cache.rb +13 -5
- data/lib/reactive_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d768497702030401fd48ec8d9149f4c74e20c725
|
4
|
+
data.tar.gz: 4fbf024a9ade1663b8b2b0106f982d39b5642c92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd59f7cc5d7704559c48099fb91c81b6ce124ad8817be2bf8a8b755d272dab3a8f2514cb3e48ddcf99dcd9ccd26b7f097fe56595ea94912f99cc5f6b65292bb
|
7
|
+
data.tar.gz: e09150e494aadd60d997b79473bd9cc9377027b4ea585f5ed243c34cf69629dc22be59e53c0aa39fc5772baea063c74b66c47d79fe4660efb3b57e00d6dfc16e
|
@@ -189,16 +189,16 @@ module ReactiveRecord
|
|
189
189
|
inverse_of = association.inverse_of
|
190
190
|
inverse_association = association.klass.reflect_on_association(inverse_of)
|
191
191
|
if inverse_association.collection?
|
192
|
-
if
|
193
|
-
attributes[attribute].attributes[inverse_of].delete(@ar_instance)
|
192
|
+
if value.nil?
|
193
|
+
attributes[attribute].attributes[inverse_of].delete(@ar_instance) unless attributes[attribute].nil?
|
194
194
|
elsif value.attributes[inverse_of]
|
195
195
|
value.attributes[inverse_of] << @ar_instance
|
196
196
|
else
|
197
197
|
value.attributes[inverse_of] = Collection.new(@model, value, inverse_association)
|
198
198
|
value.attributes[inverse_of].replace [@ar_instance]
|
199
199
|
end
|
200
|
-
elsif value
|
201
|
-
attributes[attribute].attributes[inverse_of] = nil
|
200
|
+
elsif !value.nil?
|
201
|
+
attributes[attribute].attributes[inverse_of] = nil unless attributes[attribute].nil?
|
202
202
|
value.attributes[inverse_of] = @ar_instance
|
203
203
|
React::State.set_state(value.backing_record, inverse_of, @ar_instance) unless data_loading?
|
204
204
|
elsif attributes[attribute]
|
@@ -260,15 +260,17 @@ module ReactiveRecord
|
|
260
260
|
elsif !changed_attributes.include?(attribute)
|
261
261
|
changed_attributes << attribute
|
262
262
|
end
|
263
|
+
had_key = attributes.has_key? attribute
|
263
264
|
current_value = attributes[attribute]
|
264
265
|
attributes[attribute] = value if args.count != 0
|
265
266
|
if !data_loading?
|
266
267
|
React::State.set_state(self, attribute, value)
|
267
|
-
elsif on_opal_client? and current_value.loaded? and current_value != value # this is to handle changes in already loaded server side methods
|
268
|
-
|
268
|
+
elsif on_opal_client? and had_key and current_value.loaded? and current_value != value and args.count > 0 # this is to handle changes in already loaded server side methods
|
269
|
+
puts "setting up delayed change for #{@ar_instance}.#{attribute} current: #{current_value} new: #{value}"
|
269
270
|
React::State.set_state(self, attribute, value, true)
|
270
271
|
end
|
271
272
|
if empty_before != changed_attributes.empty?
|
273
|
+
puts "setting up delayed change on record" unless on_opal_server? or data_loading?
|
272
274
|
React::State.set_state(self, "!CHANGED!", !changed_attributes.empty?, true) unless on_opal_server? or data_loading?
|
273
275
|
aggregate_owner.update_attribute(aggregate_attribute) if aggregate_owner
|
274
276
|
end
|
@@ -277,7 +277,7 @@ module ReactiveRecord
|
|
277
277
|
elsif record.changed?(attribute)
|
278
278
|
output_attributes[attribute] = value
|
279
279
|
end
|
280
|
-
end if record.changed? || (record == record_being_saved && force)
|
280
|
+
end if record.new? || record.changed? || (record == record_being_saved && force)
|
281
281
|
record_index += 1
|
282
282
|
end
|
283
283
|
[models, associations, backing_records]
|
@@ -374,6 +374,7 @@ module ReactiveRecord
|
|
374
374
|
vectors = {}
|
375
375
|
new_models = []
|
376
376
|
saved_models = []
|
377
|
+
dont_save_list = []
|
377
378
|
|
378
379
|
models.each do |model_to_save|
|
379
380
|
attributes = model_to_save[:attributes]
|
@@ -406,6 +407,7 @@ module ReactiveRecord
|
|
406
407
|
end
|
407
408
|
elsif record
|
408
409
|
# either the model is new, or its not even an active record model
|
410
|
+
dont_save_list << record unless save
|
409
411
|
keys = record.attributes.keys
|
410
412
|
attributes.each do |key, value|
|
411
413
|
if keys.include? key
|
@@ -423,54 +425,64 @@ module ReactiveRecord
|
|
423
425
|
end
|
424
426
|
|
425
427
|
puts "!!!!!!!!!!!!!!attributes updated"
|
428
|
+
ActiveRecord::Base.transaction do
|
429
|
+
associations.each do |association|
|
430
|
+
parent = reactive_records[association[:parent_id]]
|
431
|
+
next unless parent
|
432
|
+
#parent.instance_variable_set("@reactive_record_#{association[:attribute]}_changed", true) remove this????
|
433
|
+
if parent.class.reflect_on_aggregation(association[:attribute].to_sym)
|
434
|
+
puts ">>>>>>AGGREGATE>>>> #{parent.class.name}.send('#{association[:attribute]}=', #{reactive_records[association[:child_id]]})"
|
435
|
+
aggregate = reactive_records[association[:child_id]]
|
436
|
+
dont_save_list << aggregate
|
437
|
+
current_attributes = parent.send(association[:attribute]).attributes
|
438
|
+
puts "current parent attributes = #{current_attributes}"
|
439
|
+
new_attributes = aggregate.attributes
|
440
|
+
puts "current child attributes = #{new_attributes}"
|
441
|
+
merged_attributes = current_attributes.merge(new_attributes) { |k, current_attr, new_attr| aggregate.send("#{k}_changed?") ? new_attr : current_attr}
|
442
|
+
puts "merged attributes = #{merged_attributes}"
|
443
|
+
aggregate.assign_attributes(merged_attributes)
|
444
|
+
puts "aggregate attributes after merge = #{aggregate.attributes}"
|
445
|
+
parent.send("#{association[:attribute]}=", aggregate)
|
446
|
+
puts "updated is frozen? #{aggregate.frozen?}, parent attributes = #{parent.send(association[:attribute]).attributes}"
|
447
|
+
elsif parent.class.reflect_on_association(association[:attribute].to_sym).nil?
|
448
|
+
raise "Missing association :#{association[:attribute]} for #{parent.class.name}. Was association defined on opal side only?"
|
449
|
+
elsif parent.class.reflect_on_association(association[:attribute].to_sym).collection?
|
450
|
+
puts ">>>>>>>>>> #{parent.class.name}.send('#{association[:attribute]}') << #{reactive_records[association[:child_id]]})"
|
451
|
+
dont_save_list.delete(parent)
|
452
|
+
if false and parent.new?
|
453
|
+
parent.send("#{association[:attribute]}") << reactive_records[association[:child_id]] if parent.new?
|
454
|
+
puts "updated"
|
455
|
+
else
|
456
|
+
puts "skipped"
|
457
|
+
end
|
458
|
+
else
|
459
|
+
puts ">>>>ASSOCIATION>>>> #{parent.class.name}.send('#{association[:attribute]}=', #{reactive_records[association[:child_id]]})"
|
460
|
+
parent.send("#{association[:attribute]}=", reactive_records[association[:child_id]])
|
461
|
+
dont_save_list.delete(parent)
|
462
|
+
puts "updated"
|
463
|
+
end
|
464
|
+
end if associations
|
426
465
|
|
427
|
-
|
428
|
-
parent = reactive_records[association[:parent_id]]
|
429
|
-
next unless parent
|
430
|
-
#parent.instance_variable_set("@reactive_record_#{association[:attribute]}_changed", true) remove this????
|
431
|
-
if parent.class.reflect_on_aggregation(association[:attribute].to_sym)
|
432
|
-
puts ">>>>>>AGGREGATE>>>> #{parent.class.name}.send('#{association[:attribute]}=', #{reactive_records[association[:child_id]]})"
|
433
|
-
aggregate = reactive_records[association[:child_id]]
|
434
|
-
current_attributes = parent.send(association[:attribute]).attributes
|
435
|
-
puts "current parent attributes = #{current_attributes}"
|
436
|
-
new_attributes = aggregate.attributes
|
437
|
-
puts "current child attributes = #{new_attributes}"
|
438
|
-
merged_attributes = current_attributes.merge(new_attributes) { |k, current_attr, new_attr| aggregate.send("#{k}_changed?") ? new_attr : current_attr}
|
439
|
-
puts "merged attributes = #{merged_attributes}"
|
440
|
-
aggregate.assign_attributes(merged_attributes)
|
441
|
-
puts "aggregate attributes after merge = #{aggregate.attributes}"
|
442
|
-
parent.send("#{association[:attribute]}=", aggregate)
|
443
|
-
puts "updated is frozen? #{aggregate.frozen?}, parent attributes = #{parent.send(association[:attribute]).attributes}"
|
444
|
-
elsif parent.class.reflect_on_association(association[:attribute].to_sym).nil?
|
445
|
-
raise "Missing association :#{association[:attribute]} for #{parent.class.name}. Was association defined on opal side only?"
|
446
|
-
elsif parent.class.reflect_on_association(association[:attribute].to_sym).collection?
|
447
|
-
puts ">>>>>>>>>> #{parent.class.name}.send('#{association[:attribute]}') << #{reactive_records[association[:child_id]]})"
|
448
|
-
puts "Skipped (should be done by belongs to)"
|
449
|
-
else
|
450
|
-
puts ">>>>ASSOCIATION>>>> #{parent.class.name}.send('#{association[:attribute]}=', #{reactive_records[association[:child_id]]})"
|
451
|
-
parent.send("#{association[:attribute]}=", reactive_records[association[:child_id]])
|
452
|
-
puts "updated"
|
453
|
-
end
|
454
|
-
end if associations
|
455
|
-
|
456
|
-
puts "!!!!!!!!!!!!associations updated"
|
466
|
+
puts "!!!!!!!!!!!!associations updated"
|
457
467
|
|
458
|
-
|
468
|
+
#if true or save
|
459
469
|
|
460
|
-
|
470
|
+
# ActiveRecord::Base.transaction do
|
461
471
|
|
462
472
|
has_errors = false
|
463
473
|
|
474
|
+
puts "ready to start saving... dont_save_list = #{dont_save_list}"
|
475
|
+
|
464
476
|
saved_models = reactive_records.collect do |reactive_record_id, model|
|
465
477
|
puts "saving rr_id: #{reactive_record_id} model.object_id: #{model.object_id} frozen? <#{model.frozen?}>"
|
466
|
-
if model.frozen?
|
478
|
+
if model and (model.frozen? or dont_save_list.include?(model))
|
467
479
|
puts "validating frozen model #{model.class.name} #{model} (reactive_record_id = #{reactive_record_id})"
|
468
480
|
valid = model.valid?
|
469
481
|
puts "has_errors before = #{has_errors}, validate= #{validate}, !valid= #{!valid} (validate and !valid) #{validate and !valid}"
|
470
482
|
has_errors ||= (validate and !valid)
|
471
483
|
puts "validation complete errors = <#{!valid}>, #{model.errors.messages} has_errors #{has_errors}"
|
472
484
|
[reactive_record_id, model.class.name, model.attributes, (valid ? nil : model.errors.messages)]
|
473
|
-
elsif !model.id or model.changed?
|
485
|
+
elsif model and (!model.id or model.changed?)
|
474
486
|
puts "saving #{model.class.name} #{model} (reactive_record_id = #{reactive_record_id})"
|
475
487
|
saved = model.check_permission_with_acting_user(acting_user, new_models.include?(model) ? :create_permitted? : :update_permitted?).save(validate: validate)
|
476
488
|
has_errors ||= !saved
|
@@ -482,16 +494,19 @@ module ReactiveRecord
|
|
482
494
|
|
483
495
|
raise "Could not save all models" if has_errors
|
484
496
|
|
485
|
-
end
|
497
|
+
# end
|
498
|
+
if save
|
486
499
|
|
487
|
-
|
500
|
+
{success: true, saved_models: saved_models }
|
488
501
|
|
489
|
-
|
502
|
+
else
|
490
503
|
|
491
|
-
|
504
|
+
vectors.each { |vector, model| model.reload unless model.nil? or model.new_record? }
|
505
|
+
vectors
|
492
506
|
|
493
|
-
|
507
|
+
end
|
494
508
|
|
509
|
+
end
|
495
510
|
|
496
511
|
rescue Exception => e
|
497
512
|
puts "exception #{e}"
|
@@ -106,9 +106,14 @@ module ReactiveRecord
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def self.[](models, associations, vectors, acting_user)
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
result = nil
|
110
|
+
ActiveRecord::Base.transaction do
|
111
|
+
cache = new(acting_user, ReactiveRecord::Base.save_records(models, associations, acting_user, false, false))
|
112
|
+
vectors.each { |vector| cache[*vector] }
|
113
|
+
result = cache.as_json
|
114
|
+
raise ActiveRecord::Rollback
|
115
|
+
end
|
116
|
+
result
|
112
117
|
end
|
113
118
|
|
114
119
|
def clear_requests
|
@@ -182,7 +187,7 @@ module ReactiveRecord
|
|
182
187
|
self
|
183
188
|
end
|
184
189
|
rescue Exception => e
|
185
|
-
|
190
|
+
binding.pry if cache_item.value and cache_item.value != []
|
186
191
|
raise "ReactiveRecord exception caught when applying #{method} to db objects #{e}" if cache_item.value and cache_item.value != []
|
187
192
|
representative
|
188
193
|
end
|
@@ -253,7 +258,7 @@ module ReactiveRecord
|
|
253
258
|
end
|
254
259
|
elsif @ar_object.class < ActiveRecord::Base and children.is_a? Hash
|
255
260
|
@parent.as_hash({jsonize(method) => children.merge({
|
256
|
-
:id => [@ar_object.id],
|
261
|
+
:id => (method.is_a?(Array) && method.first == "new") ? [nil] : [@ar_object.id],
|
257
262
|
@ar_object.class.inheritance_column => [@ar_object[@ar_object.class.inheritance_column]],
|
258
263
|
})})
|
259
264
|
elsif method == "*all"
|
@@ -323,6 +328,9 @@ module ReactiveRecord
|
|
323
328
|
load_from_json(value, new_target) if new_target
|
324
329
|
end
|
325
330
|
#target.save if target.respond_to? :save
|
331
|
+
rescue Exception => e
|
332
|
+
`debugger`
|
333
|
+
nil
|
326
334
|
end
|
327
335
|
|
328
336
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reactive-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitch VanDuyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|