reactive-record 0.7.25 → 0.7.26

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: f84ff0051d07fb7ba4f4f6b1dde0abd213b78a4a
4
- data.tar.gz: a240b046e3f35e36d583180c85b2c968500f909c
3
+ metadata.gz: 2c15527bb6caf4a10ea5a096502f28922b327ed1
4
+ data.tar.gz: 57eaf2bda747f35a7d73f6c6921686c5e2e62097
5
5
  SHA512:
6
- metadata.gz: d534356c70ce1ed16e29bfdfc9badf5bb43a43a5d257dfde769899ee47bd6a17b2627a46e689f6eba468d19d141587f644982b3b68faf79fad5162e2837cff17
7
- data.tar.gz: bb3e9292acf24f4359eca6f3fc59ad18408c6419a8af65338e077530f9e753918ffc23d3f475011c5670a74dd067664953d256ab740f852f2c08936a61f590c7
6
+ metadata.gz: 53444409324a592f76f37a56c4164ee4f52f88df2b9912060a3e0d2807e0020d42a490650a2d9b45d2e4d12c727336bddb79e3a1c59c23d0d93dfdaf884f4a45
7
+ data.tar.gz: 68b8f20350a595919c8ef0ecae9a57b029512e27077467d0bf8b5f9bfd26a573ffda5a286c1f3a604fe6b5a303ba96c555341777b849ea24eb1e76f8685bc799
@@ -179,6 +179,13 @@ module ReactiveRecord
179
179
  end
180
180
  end
181
181
 
182
+ class << self
183
+
184
+ attr_reader :pending_fetches
185
+ attr_reader :last_fetch_at
186
+
187
+ end
188
+
182
189
  def self.schedule_fetch
183
190
  @fetch_scheduled ||= after(0.01) do
184
191
  if @pending_fetches.count > 0 # during testing we might reset the context while there are pending fetches otherwise this would never normally happen
@@ -257,13 +264,13 @@ module ReactiveRecord
257
264
  if association = record.model.reflect_on_association(attribute)
258
265
  if association.collection?
259
266
  value.each { |assoc| add_new_association.call record, attribute, assoc.backing_record }
260
- elsif value
267
+ elsif !value.nil?
261
268
  add_new_association.call record, attribute, value.backing_record
262
269
  else
263
270
  output_attributes[attribute] = nil
264
271
  end
265
272
  elsif aggregation = record.model.reflect_on_aggregation(attribute) and (aggregation.klass < ActiveRecord::Base)
266
- add_new_association.call record, attribute, value.backing_record
273
+ add_new_association.call record, attribute, value.backing_record unless value.nil?
267
274
  elsif aggregation
268
275
  new_value = aggregation.serialize(value)
269
276
  output_attributes[attribute] = new_value if record.changed?(attribute) or new_value != aggregation.serialize(record.synced_attributes[attribute])
@@ -373,7 +380,13 @@ module ReactiveRecord
373
380
  model = Object.const_get(model_to_save[:model])
374
381
  id = attributes.delete(model.primary_key) if model.respond_to? :primary_key # if we are saving existing model primary key value will be present
375
382
  vector = model_to_save[:vector]
376
- vector[0] = vector[0].constantize
383
+ vector = [vector[0].constantize] + vector[1..-1].collect do |method|
384
+ if method.is_a?(Array) and method.first == "find_by_id"
385
+ ["find", method.last]
386
+ else
387
+ method
388
+ end
389
+ end
377
390
  reactive_records[model_to_save[:id]] = vectors[vector] = record = find_record(model, id, vector, save)
378
391
  if record and record.respond_to?(:id) and record.id
379
392
  # we have an already exising activerecord model
@@ -25,6 +25,18 @@ module ReactiveRecord
25
25
  @loads_pending = true
26
26
  end
27
27
 
28
+ def self.check_loads_pending
29
+ if @loads_pending
30
+ if Base.pending_fetches.count > 0
31
+ true
32
+ else # this happens when for example loading foo.x results in somebody looking at foo.y while foo.y is still being loaded
33
+ ReactiveRecord::WhileLoading.loaded_at Base.last_fetch_at
34
+ ReactiveRecord::WhileLoading.quiet!
35
+ false
36
+ end
37
+ end
38
+ end
39
+
28
40
  def self.run_blocks_to_load(failure = nil)
29
41
  if @blocks_to_load
30
42
  blocks_to_load = @blocks_to_load
@@ -34,7 +46,7 @@ module ReactiveRecord
34
46
  @load_stack << @loads_pending
35
47
  @loads_pending = nil
36
48
  result = promise_and_block.last.call(failure)
37
- if @loads_pending and !failure
49
+ if check_loads_pending and !failure
38
50
  @blocks_to_load << promise_and_block
39
51
  else
40
52
  promise_and_block.first.resolve result
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.25"
2
+ VERSION = "0.7.26"
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.25
4
+ version: 0.7.26
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-10 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails