object_attorney 2.1.1 → 2.1.2
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 +8 -8
- data/lib/object_attorney/nested_objects.rb +15 -2
- data/lib/object_attorney/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDY1NGY3N2NlMjUyNDg4N2E2NGY2MTExMjhiNDg4YmU1NGRkM2E1ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWVjYjNkZGJkMDVlNmRhZmZlY2E0NDQ4Y2MwYjYyZTA4ZTYzNGJmNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmZhNTQ3NTg4Y2FjYWExM2M1ZDE1OGU2ODc2YTMxYmY5ZjhlYTgzMDQ3YjJm
|
10
|
+
NWE2NmYyN2FjMWFmOTIzNjA5ZDk3MjdhODhlZTU0YzVmOWRkNTEyYzViMmI0
|
11
|
+
YjU3OWJkNTA4ZmZlMmNjNTEyYzM2ZGYzN2E1ZjNmM2ZiMDk1M2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODAwYjliMmU0M2Y4YjEwOTg0ZGMxMzU5NDkxYjg5ODgzZDk2M2JmNGE2Y2M1
|
14
|
+
ZTE4OTJiZTdiODIzNmZmYTllN2VmYWViZmNlYzMzMDk0ZTkyODYyOGQ5NjE4
|
15
|
+
Zjc4NmVhNWYyMTdlYTczMDRiNzY1ODFlNDMzOThkZjMwZDRmMmM=
|
@@ -141,13 +141,26 @@ module ObjectAttorney
|
|
141
141
|
def build_nested_object(nested_object_name, attributes = {})
|
142
142
|
reflection = self.class.reflect_on_association(nested_object_name)
|
143
143
|
|
144
|
-
new_nested_object = reflection.klass.new(attributes)
|
145
|
-
|
144
|
+
new_nested_object = build_from_represented_object(reflection, nested_object_name, attributes) || reflection.klass.new(attributes)
|
145
|
+
|
146
146
|
populate_foreign_key(self, new_nested_object, reflection, :has_many)
|
147
147
|
|
148
148
|
new_nested_object
|
149
149
|
end
|
150
150
|
|
151
|
+
def build_from_represented_object(reflection, nested_object_name, attributes)
|
152
|
+
return nil if represented_object.blank?
|
153
|
+
return nil if reflection.klass != self.class.represented_object_class.reflect_on_association(nested_object_name).klass
|
154
|
+
|
155
|
+
build_method = "build_#{nested_object_name}"
|
156
|
+
|
157
|
+
if represented_object.respond_to?(build_method)
|
158
|
+
represented_object.send(build_method, attributes)
|
159
|
+
else
|
160
|
+
represented_object.send(nested_object_name).build(attributes)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
151
164
|
def existing_nested_objects(nested_object_name)
|
152
165
|
nested_association_klass = self.class.reflect_on_association(nested_object_name).klass
|
153
166
|
|