reactive-record 0.7.30 → 0.7.31
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b418800c8ef12fe914f24f8a948bc7a923ff944d
|
4
|
+
data.tar.gz: 93880104e8ae61b61f98f49d334fb2523f908274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03c0edb07af6406c102deefbf5671f64be507ad6d92a81971eb0adfa2ce28a8542b48d3e63da6af219338225e961aa22e07b841e9e8412626df16d365552f7ce
|
7
|
+
data.tar.gz: 2dcefccee1f3b7deb11d4ef26736438dfc8fb30a1f6c28172d9927d1229a5a3834cb648abbc46bd1fc74ff9a3985c8c85a38ded7b07d66199f3257e80d69d765
|
@@ -94,12 +94,12 @@ module ReactiveRecord
|
|
94
94
|
|
95
95
|
include React::Component
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
param :loading
|
98
|
+
param :loaded_children
|
99
|
+
param :loading_children
|
100
|
+
param :element_type
|
101
|
+
param :element_props
|
102
|
+
param :display, default: ""
|
103
103
|
|
104
104
|
class << self
|
105
105
|
|
@@ -169,28 +169,31 @@ module ReactiveRecord
|
|
169
169
|
db_cache << self
|
170
170
|
end
|
171
171
|
|
172
|
-
def apply_method_to_cache(method
|
172
|
+
def apply_method_to_cache(method)
|
173
173
|
@db_cache.inject(nil) do | representative, cache_item |
|
174
174
|
if cache_item.vector == vector
|
175
175
|
if @ar_object.class < ActiveRecord::Base and @ar_object.attributes.has_key?(method)
|
176
176
|
@ar_object.check_permission_with_acting_user(acting_user, :view_permitted?, method)
|
177
177
|
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
178
|
+
if method == "*"
|
179
|
+
cache_item.apply_star || representative
|
180
|
+
elsif method == "*all"
|
181
|
+
cache_item.build_new_cache_item(cache_item.value.collect { |record| record.id }, method, method)
|
182
|
+
elsif method == "*count"
|
183
|
+
cache_item.build_new_cache_item(cache_item.value.count, method, method)
|
184
|
+
elsif preloaded_value = @preloaded_records[cache_item.absolute_vector + [method]]
|
185
|
+
cache_item.build_new_cache_item(preloaded_value, method, method)
|
186
|
+
elsif aggregation = cache_item.aggregation?(method)
|
187
|
+
cache_item.build_new_cache_item(aggregation.mapping.collect { |attribute, accessor| cache_item.value[attribute] }, method, method)
|
188
|
+
else
|
189
|
+
begin
|
190
|
+
cache_item.build_new_cache_item(cache_item.value.send(*method), method, method)
|
191
|
+
rescue Exception => e
|
192
|
+
if cache_item.value and cache_item.value != []
|
193
|
+
raise "ReactiveRecord exception caught when applying #{method} to db object #{cache_item.value}: #{e}"
|
194
|
+
else
|
195
|
+
representative
|
196
|
+
end
|
194
197
|
end
|
195
198
|
end
|
196
199
|
else
|
@@ -199,46 +202,54 @@ module ReactiveRecord
|
|
199
202
|
end
|
200
203
|
end
|
201
204
|
|
202
|
-
def
|
203
|
-
if method.is_a?
|
204
|
-
|
205
|
-
|
206
|
-
|
205
|
+
def aggregation?(method)
|
206
|
+
if method.is_a?(String) && value.class.respond_to?(:reflect_on_aggregation)
|
207
|
+
aggregation = value.class.reflect_on_aggregation(method.to_sym)
|
208
|
+
if aggregation && !(aggregation.klass < ActiveRecord::Base) && value.send(method)
|
209
|
+
aggregation
|
210
|
+
end
|
207
211
|
end
|
208
|
-
new_vector = vector + [method]
|
209
|
-
@db_cache.detect { |cached_item| cached_item.vector == new_vector} || build_new_instances(method)
|
210
212
|
end
|
211
213
|
|
212
|
-
def
|
213
|
-
if
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
i = -1
|
220
|
-
@ar_object.inject(nil) do | value, record | # just using inject so we will return the last value
|
221
|
-
i += 1
|
222
|
-
apply_method_to_cache(method, "*#{i}") { |cache_item| @preloaded_records[cache_item.absolute_vector + ["*#{i}"]] || record }
|
223
|
-
end
|
224
|
-
else
|
225
|
-
apply_method_to_cache(method, method) {[]}
|
226
|
-
end
|
227
|
-
else
|
228
|
-
apply_method_to_cache(method, method) do |cache_item|
|
229
|
-
if preloaded_value = @preloaded_records[cache_item.absolute_vector + [method]]
|
230
|
-
preloaded_value
|
231
|
-
elsif method.is_a? String and cache_item.value.class.respond_to?(:reflect_on_aggregation) and
|
232
|
-
aggregation = cache_item.value.class.reflect_on_aggregation(method.to_sym) and !(aggregation.klass < ActiveRecord::Base) and
|
233
|
-
cache_item.value.send(method)
|
234
|
-
aggregation.mapping.collect { |attribute, accessor| cache_item.value[attribute] }
|
214
|
+
def apply_star
|
215
|
+
if value && value.length > 0
|
216
|
+
i = -1
|
217
|
+
value.inject(nil) do | representative, ar_object |
|
218
|
+
i += 1
|
219
|
+
if preloaded_value = @preloaded_records[absolute_vector + ["*#{i}"]]
|
220
|
+
build_new_cache_item(preloaded_value, "*", "*#{i}")
|
235
221
|
else
|
236
|
-
|
222
|
+
build_new_cache_item(ar_object, "*", "*#{i}")
|
237
223
|
end
|
238
224
|
end
|
225
|
+
else
|
226
|
+
build_new_cache_item([], "*", "*")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def build_new_cache_item(new_ar_object, method, absolute_method)
|
231
|
+
new_parent = self
|
232
|
+
self.clone.instance_eval do
|
233
|
+
@vector = @vector + [method] # don't push it on since you need a new vector!
|
234
|
+
@absolute_vector = @absolute_vector + [absolute_method]
|
235
|
+
@ar_object = new_ar_object
|
236
|
+
@db_cache << self
|
237
|
+
@parent = new_parent
|
238
|
+
@root = new_parent.root
|
239
|
+
self
|
239
240
|
end
|
240
241
|
end
|
241
242
|
|
243
|
+
def apply_method(method)
|
244
|
+
if method.is_a? Array and method.first == "find_by_id"
|
245
|
+
method[0] = "find"
|
246
|
+
elsif method.is_a? String and method =~ /^\*[0-9]+$/
|
247
|
+
method = "*"
|
248
|
+
end
|
249
|
+
new_vector = vector + [method]
|
250
|
+
@db_cache.detect { |cached_item| cached_item.vector == new_vector} || apply_method_to_cache(method)
|
251
|
+
end
|
252
|
+
|
242
253
|
def jsonize(method)
|
243
254
|
# sadly standard json converts {[:foo, nil] => 123} to {"['foo', nil]": 123}
|
244
255
|
# luckily [:foo, nil] does convert correctly
|
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.31
|
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-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|