hyper-mesh 1.0.0.lap27 → 1.0.0.lap28
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/.gitignore +1 -0
- data/.rubocop.yml +6 -2
- data/Gemfile +0 -1
- data/Rakefile +2 -2
- data/hyper-mesh.gemspec +1 -1
- data/lib/active_record_base.rb +39 -27
- data/lib/hyper-mesh.rb +6 -1
- data/lib/hypermesh/version.rb +1 -1
- data/lib/object/tap.rb +7 -0
- data/lib/reactive_record/active_record/associations.rb +14 -3
- data/lib/reactive_record/active_record/base.rb +1 -2
- data/lib/reactive_record/active_record/class_methods.rb +120 -67
- data/lib/reactive_record/active_record/error.rb +17 -12
- data/lib/reactive_record/active_record/errors.rb +374 -0
- data/lib/reactive_record/active_record/instance_methods.rb +58 -67
- data/lib/reactive_record/active_record/reactive_record/backing_record_inspector.rb +1 -4
- data/lib/reactive_record/active_record/reactive_record/base.rb +129 -234
- data/lib/reactive_record/active_record/reactive_record/collection.rb +51 -18
- data/lib/reactive_record/active_record/reactive_record/column_types.rb +5 -3
- data/lib/reactive_record/active_record/reactive_record/dummy_value.rb +6 -4
- data/lib/reactive_record/active_record/reactive_record/getters.rb +133 -0
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +99 -87
- data/lib/reactive_record/active_record/reactive_record/lookup_tables.rb +54 -0
- data/lib/reactive_record/active_record/reactive_record/operations.rb +2 -1
- data/lib/reactive_record/active_record/reactive_record/scoped_collection.rb +1 -1
- data/lib/reactive_record/active_record/reactive_record/setters.rb +194 -0
- data/lib/reactive_record/active_record/reactive_record/while_loading.rb +4 -5
- data/lib/reactive_record/active_record_error.rb +4 -0
- data/lib/reactive_record/broadcast.rb +55 -18
- data/lib/reactive_record/permissions.rb +5 -4
- data/lib/reactive_record/scope_description.rb +14 -6
- data/lib/reactive_record/server_data_cache.rb +119 -70
- metadata +16 -13
- data/lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb +0 -189
@@ -1,189 +0,0 @@
|
|
1
|
-
module ReactiveRecord
|
2
|
-
# methods to update aggregrations and relations, called from reactive_set!
|
3
|
-
class Base
|
4
|
-
def update_aggregate(attribute, value)
|
5
|
-
# if attribute is an aggregate then
|
6
|
-
# match and update all fields in the aggregate from value and return true
|
7
|
-
# otherwise return false
|
8
|
-
aggregation = @model.reflect_on_aggregation(attribute)
|
9
|
-
return false unless aggregation && (aggregation.klass < ActiveRecord::Base)
|
10
|
-
if value
|
11
|
-
value_attributes = value.backing_record.attributes
|
12
|
-
update_mapped_attributes(aggregation) { |attr| value_attributes[attr] }
|
13
|
-
else
|
14
|
-
update_mapped_attributes(aggregation) { nil }
|
15
|
-
end
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
def update_mapped_attributes(aggregation)
|
20
|
-
# insure the aggregate attr is initialized, clear the virt flag, the caller
|
21
|
-
# will yield each of the matching attribute values
|
22
|
-
attr = aggregation.attribute
|
23
|
-
attributes[attr] ||= aggregation.klass.new if new?
|
24
|
-
aggregate_record = attributes[attr]
|
25
|
-
raise 'uninitialized aggregate attribute - should never happen' unless aggregate_record
|
26
|
-
aggregate_backing_record = aggregate_record.backing_record
|
27
|
-
aggregate_backing_record.virgin = false
|
28
|
-
aggregation.mapped_attributes.each do |mapped_attribute|
|
29
|
-
aggregate_backing_record.update_attribute(mapped_attribute, yield(mapped_attribute))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def update_relationships(attr, value)
|
34
|
-
# update the inverse relationship, and any through relationships
|
35
|
-
# return either the value, or in the case of updating a collection
|
36
|
-
# return the new collection after value is overwritten into it.
|
37
|
-
association = @model.reflect_on_association(attr)
|
38
|
-
return value unless association
|
39
|
-
if association.collection?
|
40
|
-
overwrite_has_many_collection(association, value)
|
41
|
-
else
|
42
|
-
update_belongs_to_association(association, value)
|
43
|
-
value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def overwrite_has_many_collection(association, value)
|
48
|
-
# create a new collection to hold value, shove it in, and return the new collection
|
49
|
-
# the replace method will take care of updating the inverse belongs_to links as
|
50
|
-
# the collection is overwritten
|
51
|
-
Collection.new(association.klass, @ar_instance, association).tap do |collection|
|
52
|
-
collection.replace(value || [])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def update_belongs_to_association(association, value)
|
57
|
-
# either update update the inverse has_many collection or individual belongs_to
|
58
|
-
# inverse values
|
59
|
-
if association.inverse.collection?
|
60
|
-
update_has_many_through_associations(association, value)
|
61
|
-
update_inverse_collections(association, value)
|
62
|
-
else
|
63
|
-
update_inverse_attribute(association, value)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def update_inverse_attribute(association, value)
|
68
|
-
# when updating the inverse attribute of a belongs_to that is itself a belongs_to
|
69
|
-
# (i.e. 1-1 relationship) we clear the existing inverse value and then
|
70
|
-
# write the current record to the new value
|
71
|
-
current_value = attributes[association.attribute]
|
72
|
-
inverse_attr = association.inverse.attribute
|
73
|
-
current_value.attributes[inverse_attr] = nil unless current_value.nil?
|
74
|
-
return if value.nil?
|
75
|
-
value.attributes[inverse_attr] = @ar_instance
|
76
|
-
return if data_loading?
|
77
|
-
React::State.set_state(value.backing_record, inverse_attr, @ar_instance)
|
78
|
-
end
|
79
|
-
|
80
|
-
def update_inverse_collections(association, value)
|
81
|
-
# when updating an inverse attribute of a belongs_to that is a has_many (i.e. a collection)
|
82
|
-
# we need to first remove the current associated value (if non-nil), then add the new
|
83
|
-
# value to the collection. If the inverse collection is not yet initialized we do it here.
|
84
|
-
current_value = attributes[association.attribute]
|
85
|
-
inverse_attr = association.inverse.attribute
|
86
|
-
if value.nil?
|
87
|
-
current_value.attributes[inverse_attr].delete(@ar_instance) unless current_value.nil?
|
88
|
-
else
|
89
|
-
value.backing_record.push_onto_collection(@model, association.inverse, @ar_instance)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def push_onto_collection(model, association, ar_instance)
|
94
|
-
attributes[association.attribute] ||= Collection.new(model, @ar_instance, association)
|
95
|
-
attributes[association.attribute] << ar_instance
|
96
|
-
end
|
97
|
-
|
98
|
-
def update_has_many_through_associations(association, value)
|
99
|
-
association.through_associations.each { |ta| update_through_association(ta, value) }
|
100
|
-
association.source_associations.each { |sa| update_source_association(sa, value) }
|
101
|
-
end
|
102
|
-
|
103
|
-
def update_through_association(ta, new_belongs_to_value)
|
104
|
-
# appointment.doctor = doctor_new_value (i.e. through association is changing)
|
105
|
-
# means appointment.doctor_new_value.patients << appointment.patient
|
106
|
-
# and we have to appointment.doctor_current_value.patients.delete(appointment.patient)
|
107
|
-
source_value = attributes[ta.source]
|
108
|
-
current_belongs_to_value = attributes[ta.inverse.attribute]
|
109
|
-
return unless source_value
|
110
|
-
unless current_belongs_to_value.nil? || current_belongs_to_value.attributes[ta.attribute].nil?
|
111
|
-
current_belongs_to_value.attributes[ta.attribute].delete(source_value)
|
112
|
-
end
|
113
|
-
return unless new_belongs_to_value
|
114
|
-
new_belongs_to_value.attributes[ta.attribute] ||= Collection.new(ta.klass, new_belongs_to_value, ta)
|
115
|
-
new_belongs_to_value.attributes[ta.attribute] << source_value
|
116
|
-
end
|
117
|
-
|
118
|
-
def update_source_association(sa, new_source_value)
|
119
|
-
# appointment.patient = patient_value (i.e. source is changing)
|
120
|
-
# means appointment.doctor.patients.delete(appointment.patient)
|
121
|
-
# means appointment.doctor.patients << patient_value
|
122
|
-
belongs_to_value = attributes[sa.inverse.attribute]
|
123
|
-
current_source_value = attributes[sa.source]
|
124
|
-
return unless belongs_to_value
|
125
|
-
unless belongs_to_value.attributes[sa.attribute].nil? || current_source_value.nil?
|
126
|
-
belongs_to_value.attributes[sa.attribute].delete(current_source_value)
|
127
|
-
end
|
128
|
-
return unless new_source_value
|
129
|
-
belongs_to_value.attributes[sa.attribute] ||= Collection.new(sa.klass, belongs_to_value, sa)
|
130
|
-
belongs_to_value.attributes[sa.attribute] << new_source_value
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# def reactive_set!(attribute, value)
|
136
|
-
# @virgin = false unless data_loading?
|
137
|
-
# unless @destroyed or (!(attributes[attribute].is_a? DummyValue) and attributes.has_key?(attribute) and attributes[attribute] == value)
|
138
|
-
# if association = @model.reflect_on_association(attribute)
|
139
|
-
# if association.collection?
|
140
|
-
# collection = Collection.new(association.klass, @ar_instance, association)
|
141
|
-
# collection.replace(value || [])
|
142
|
-
# value = collection
|
143
|
-
# else
|
144
|
-
# inverse_of = association.inverse_of
|
145
|
-
# inverse_association = association.klass.reflect_on_association(inverse_of)
|
146
|
-
# if inverse_association.collection?
|
147
|
-
# if value.nil?
|
148
|
-
# attributes[attribute].attributes[inverse_of].delete(@ar_instance) unless attributes[attribute].nil?
|
149
|
-
# elsif value.attributes[inverse_of]
|
150
|
-
# value.attributes[inverse_of] << @ar_instance
|
151
|
-
# else
|
152
|
-
# value.attributes[inverse_of] = Collection.new(@model, value, inverse_association)
|
153
|
-
# # value.attributes[inverse_of].replace [@ar_instance]
|
154
|
-
# # why was the above not just the below???? fixed 10/28/2016
|
155
|
-
# value.attributes[inverse_of] << @ar_instance
|
156
|
-
# end
|
157
|
-
# elsif !value.nil?
|
158
|
-
# attributes[attribute].attributes[inverse_of] = nil unless attributes[attribute].nil?
|
159
|
-
# value.attributes[inverse_of] = @ar_instance
|
160
|
-
# React::State.set_state(value.backing_record, inverse_of, @ar_instance) unless data_loading?
|
161
|
-
# elsif attributes[attribute]
|
162
|
-
# attributes[attribute].attributes[inverse_of] = nil
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
# elsif aggregation = @model.reflect_on_aggregation(attribute) and (aggregation.klass < ActiveRecord::Base)
|
166
|
-
#
|
167
|
-
# if new?
|
168
|
-
# attributes[attribute] ||= aggregation.klass.new
|
169
|
-
# elsif !attributes[attribute]
|
170
|
-
# raise "uninitialized aggregate attribute - should never happen"
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# aggregate_record = attributes[attribute].backing_record
|
174
|
-
# aggregate_record.virgin = false
|
175
|
-
#
|
176
|
-
# if value
|
177
|
-
# value_attributes = value.backing_record.attributes
|
178
|
-
# aggregation.mapped_attributes.each { |mapped_attribute| aggregate_record.update_attribute(mapped_attribute, value_attributes[mapped_attribute])}
|
179
|
-
# else
|
180
|
-
# aggregation.mapped_attributes.each { |mapped_attribute| aggregate_record.update_attribute(mapped_attribute, nil) }
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# return attributes[attribute]
|
184
|
-
#
|
185
|
-
# end
|
186
|
-
# update_attribute(attribute, value)
|
187
|
-
# end
|
188
|
-
# value
|
189
|
-
# end
|