reactive-record 0.7.30 → 0.7.31

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
  SHA1:
3
- metadata.gz: b6bb1cc3265c0141b9757c88ceb4e7fcbf958d00
4
- data.tar.gz: 6c55106b465a686d47393255977e7044d1841ce6
3
+ metadata.gz: b418800c8ef12fe914f24f8a948bc7a923ff944d
4
+ data.tar.gz: 93880104e8ae61b61f98f49d334fb2523f908274
5
5
  SHA512:
6
- metadata.gz: 1721fdfe1bc81b417c9c722efa2b1ec89a8726cedf474d5811a2cd3bdfba30506343d3b33c54115a575ca8d53f3596ffbcaf3f702993fadee41f86e424fa8852
7
- data.tar.gz: 42145c75a12201d4c8d699019dc16f12a86a4f6c0d55e16457c82f3cf6033d98091b5c8fd4496f94feaa888502fd3bccecec62c0fa00c78e5ce688f7a079d09c
6
+ metadata.gz: 03c0edb07af6406c102deefbf5671f64be507ad6d92a81971eb0adfa2ce28a8542b48d3e63da6af219338225e961aa22e07b841e9e8412626df16d365552f7ce
7
+ data.tar.gz: 2dcefccee1f3b7deb11d4ef26736438dfc8fb30a1f6c28172d9927d1229a5a3834cb648abbc46bd1fc74ff9a3985c8c85a38ded7b07d66199f3257e80d69d765
@@ -224,8 +224,6 @@ module ReactiveRecord
224
224
  {record.class.inheritance_column => record[record.class.inheritance_column]}
225
225
  end
226
226
 
227
- # save records
228
-
229
227
  if RUBY_ENGINE == 'opal'
230
228
 
231
229
  def self.gather_records(records_to_process, force, record_being_saved)
@@ -94,12 +94,12 @@ module ReactiveRecord
94
94
 
95
95
  include React::Component
96
96
 
97
- required_param :loading
98
- required_param :loaded_children
99
- required_param :loading_children
100
- required_param :element_type
101
- required_param :element_props
102
- optional_param :display, default: ""
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, absolute_method, &block)
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
- begin
179
- new_ar_object = yield cache_item
180
- cache_item.clone.instance_eval do
181
- @vector = @vector + [method] # don't push it on since you need a new vector!
182
- @absolute_vector = @absolute_vector + [absolute_method]
183
- @ar_object = new_ar_object
184
- @db_cache << self
185
- @parent = cache_item
186
- @root = cache_item.root
187
- self
188
- end
189
- rescue Exception => e
190
- if cache_item.value and cache_item.value != []
191
- raise "ReactiveRecord exception caught when applying #{method} to db object #{cache_item.value}: #{e}"
192
- else
193
- representative
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 apply_method(method)
203
- if method.is_a? Array and method.first == "find_by_id"
204
- method[0] = "find"
205
- elsif method.is_a? String and method =~ /^\*[0-9]+$/
206
- method = "*"
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 build_new_instances(method)
213
- if method == "*all"
214
- apply_method_to_cache("*all", "*all") { |cache_item| cache_item.value.collect { |record| record.id } }
215
- elsif method == "*count"
216
- apply_method_to_cache("*count", "*count") { |cache_item| cache_item.value.count }
217
- elsif method == "*"
218
- if @ar_object and @ar_object.length > 0
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
- cache_item.value.send(*method)
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
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.30"
2
+ VERSION = "0.7.31"
3
3
  end
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.30
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-04 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails