reactive-record 0.7.16 → 0.7.17

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: 139439c144b766200fccb72d67240cbfec0d6eae
4
- data.tar.gz: 1d67f45f99d68e4e2dd0ac5db2ee88885b491e80
3
+ metadata.gz: 906f180ce48df5a17368e98b8fc2dd12cadbe37f
4
+ data.tar.gz: 40966ab4582c08edd15d88625dd5de102ea8cfc0
5
5
  SHA512:
6
- metadata.gz: 4389f9eeecb8e5da8ff5788bdcb5886b2f086111e8a7ca7620e65e78cec26fcdb2b371fb2ab2d38fa0a7f3517a675478557a1a157915e99a93848e6d526b105d
7
- data.tar.gz: 1c647b32c2b98182e8e8dbd12672ce1faca07bce3613405baec06c8c30ed56a21f15e27d342448fdd10969dddcd82b40d36acb04669693ea5116262b83969e63
6
+ metadata.gz: 955d731a1ebf9cbaa76cf0ea44ef7e7cd9b1598b5e7662f28057055c4590de02b7bf9431e00f33cbb6733299bde1ecbf1cea2cff9d85b46fcd9f821f7bdf4e2a
7
+ data.tar.gz: 2f6bf61dfdfefcf9f90ef9a2b615612ef0014cbb1820b6103d28964a6f3058fad8606cce5be9f64ee45d7af4eab1fb682501d47a1e568d764813247b6b0171e1
@@ -1,38 +1,40 @@
1
1
  module ActiveRecord
2
-
2
+
3
3
  class Base
4
-
4
+
5
5
  def self.reflect_on_all_aggregations
6
6
  base_class.instance_eval { @aggregations ||= [] }
7
7
  end
8
-
8
+
9
9
  def self.reflect_on_aggregation(attribute)
10
10
  reflect_on_all_aggregations.detect { |aggregation| aggregation.attribute == attribute }
11
11
  end
12
-
12
+
13
13
  end
14
-
14
+
15
15
  module Aggregations
16
-
16
+
17
17
  class AggregationReflection
18
-
18
+
19
19
  attr_reader :klass_name
20
20
  attr_reader :attribute
21
-
21
+ attr_reader :mapped_attributes
22
+
22
23
  def initialize(owner_class, macro, name, options = {})
23
24
  owner_class.reflect_on_all_aggregations << self
24
25
  @owner_class = owner_class
25
26
  @klass_name = options[:class_name] || name.camelize
26
27
  @attribute = name
28
+ @mapped_attributes = options[:mapping].collect &:last
27
29
  end
28
-
30
+
29
31
  def klass
30
32
  @klass ||= Object.const_get(@klass_name)
31
33
  end
32
-
34
+
33
35
  end
34
-
36
+
35
37
  end
36
-
37
-
38
- end
38
+
39
+
40
+ end
@@ -1,9 +1,9 @@
1
1
  module ActiveRecord
2
2
  class Base
3
-
3
+
4
4
  extend ClassMethods
5
-
5
+
6
6
  include InstanceMethods
7
-
7
+
8
8
  end
9
- end
9
+ end
@@ -17,7 +17,7 @@ module ActiveRecord
17
17
  self.class.load_data do
18
18
  hash.each do |attribute, value|
19
19
  unless attribute == primary_key
20
- reactive_set!(attribute, value) unless attribute == primary_key
20
+ reactive_set!(attribute, value)
21
21
  changed_attributes << attribute
22
22
  end
23
23
  end
@@ -52,6 +52,10 @@ module ActiveRecord
52
52
  @backing_record.changed?
53
53
  end
54
54
 
55
+ def dup
56
+ self.class.new(self.attributes)
57
+ end
58
+
55
59
  def ==(ar_instance)
56
60
  @backing_record == ar_instance.instance_eval { @backing_record }
57
61
  end
@@ -100,9 +100,17 @@ module ReactiveRecord
100
100
  record = new model
101
101
  record.vector = vector
102
102
  end
103
- record.aggregate_owner = aggregate_owner
104
- record.aggregate_attribute = vector.last
103
+
105
104
  record.ar_instance ||= infer_type_from_hash(model, record.attributes).new(record)
105
+
106
+ if aggregate_owner
107
+ record.aggregate_owner = aggregate_owner
108
+ record.aggregate_attribute = vector.last
109
+ aggregate_owner.attributes[vector.last] = record.ar_instance
110
+ end
111
+
112
+ record.ar_instance
113
+
106
114
  end
107
115
 
108
116
  def initialize(model, hash = {}, ar_instance = nil)
@@ -180,11 +188,23 @@ module ReactiveRecord
180
188
  attributes[attribute].attributes[inverse_of] = nil
181
189
  end
182
190
  end
183
- elsif @model.reflect_on_aggregation(attribute)
184
- attributes[attribute].instance_variable_get(:@backing_record).aggregate_owner = nil if attributes[attribute]
185
- aggregate = value.instance_variable_get(:@backing_record)
186
- aggregate.aggregate_owner = self
187
- aggregate.aggregate_attribute = attribute
191
+ elsif aggregation = @model.reflect_on_aggregation(attribute)
192
+
193
+ unless attributes[attribute]
194
+ raise "unitialized aggregate attribute - should never happen"
195
+ end
196
+
197
+ aggregate_record = attributes[attribute].instance_variable_get(:@backing_record)
198
+
199
+ if value
200
+ value_attributes = value.instance_variable_get(:@backing_record).attributes
201
+ aggregation.mapped_attributes.each { |mapped_attribute| aggregate_record.update_attribute(mapped_attribute, value_attributes[mapped_attribute])}
202
+ else
203
+ aggregation.mapped_attributes.each { |mapped_attribute| aggregate_record.update_attribute(mapped_attribute, nil) }
204
+ end
205
+
206
+ return attributes[attribute]
207
+
188
208
  end
189
209
  update_attribute(attribute, value)
190
210
  end
@@ -334,7 +334,7 @@ module ReactiveRecord
334
334
  puts "current parent attributes = #{current_attributes}"
335
335
  new_attributes = aggregate.attributes
336
336
  puts "current child attributes = #{new_attributes}"
337
- merged_attributes = current_attributes.merge(new_attributes) { |k, n, o| n or o }
337
+ merged_attributes = current_attributes.merge(new_attributes) { |k, current_attr, new_attr| aggregate.send("#{k}_changed?") ? new_attr : current_attr}
338
338
  puts "merged attributes = #{merged_attributes}"
339
339
  aggregate.assign_attributes(merged_attributes)
340
340
  puts "aggregate attributes after merge = #{aggregate.attributes}"
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.16"
2
+ VERSION = "0.7.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.16
4
+ version: 0.7.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn