object_attorney 2.10.1 → 2.10.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjBlYjkxZTVkYTM4OTdjZTAwNTVjMTM3MjAwNGRlOTg4YTg4NTE0Zg==
4
+ Mzg5Y2Q0NjA0NGIzMGUzY2ZjZjc0NTYxNzQyODAxMWQzMTE3NDIxNg==
5
5
  data.tar.gz: !binary |-
6
- ODQ0NTY1NmU5MDBjOTEyNTBkNWI4YjMyYTQ0YWY5YzJmMjUyMzUzZA==
6
+ Yzg3ZDI0N2JjNmYxMTMzZDMzOTc3NzQxNzNmNmRmMzk4ZGQxOWY5Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGZhOGIyODdjYzNmMjc3ODgyZmZkMzM2MzUzYzZiMTExZWRmOTczMmUyNDFm
10
- YjJkNDEyZDNhMzg4OWMwZDNhY2ZjZjQyZDJhMGRhM2NmMWQ2MmNiZTAwYzZm
11
- MzQ0NGVhYmEwYzgwYWRkOWZkYjMwYTUyMWExYTRjZDkxNTgyNWY=
9
+ OGU4ZGQ1MjEzYmNiYTUxYjMyZjIyN2Q4ZWZkYzcyZDYwNTAxNjczNjc0NTRk
10
+ YzQ3M2Y1OTA1MTVmOWFiZmRhNmYwMTZlNDA1MDg4YTU1OWNhODA1MTUxOTM1
11
+ MGViNzZkNWE4NTU5MzU0MDc4YjQzMjg4MjZmMDhjYjQwNzhiMmE=
12
12
  data.tar.gz: !binary |-
13
- MDEwZjdiNmFiZDIzZWZhMDMyMzk3NzRmMDQzNTNiNmQwNjI5NTIyMjQ1ODEx
14
- MjlkN2ZkNDU1ZmQ0MDU4ZjgwNmZjNjUyMTJmOGQyMDJlYmZkMDM1MzEyYTg3
15
- Yzc1ZGM1N2MwOTM5OGUzNWZhOTYwYjZhYTliZTg3NmZjYTJmNWI=
13
+ M2U4MGJkZTc4YjU3NmFlZTU3N2UyZDg4ZjE0OWZjMTM0YTE3ZGZiMjBkOTBk
14
+ MzM2NzE5M2Y3OTExNzYzYzA3MGE3YzI2ZTNlMDEwOTcwNWUwNzcyZDNkODNi
15
+ NjlhMTQ2Y2Y2YjgyNDNjZTA5NzQyZmFhMWExNjY1ZTNiODE5MzU=
@@ -155,14 +155,18 @@ module ObjectAttorney
155
155
  end
156
156
  end
157
157
 
158
- def build_nested_object(nested_object_name, attributes = {})
158
+ def build_nested_object(nested_object_name, attributes = {}, new_nested_object = nil)
159
159
  attributes = attributes.symbolize_keys
160
160
  reflection = self.class.reflect_on_association(nested_object_name)
161
161
 
162
162
  return nil if reflection.options[:new_records] == false
163
163
 
164
- if reflection.options[:standalone] == true || !can_represented_object_build_nested?(reflection, nested_object_name)
164
+ if new_nested_object.present?
165
+ new_nested_object = assign_attributes_or_build_nested_object(reflection, attributes, new_nested_object)
166
+
167
+ elsif reflection.options[:standalone] == true || !can_represented_object_build_nested?(reflection, nested_object_name)
165
168
  new_nested_object = reflection.klass.new(attributes)
169
+
166
170
  else
167
171
  new_nested_object = build_from_represented_object(reflection, nested_object_name)
168
172
 
@@ -255,7 +259,7 @@ module ObjectAttorney
255
259
  self.send(:attr_accessor, "#{nested_object_name}_attributes".to_sym)
256
260
 
257
261
  define_method(nested_object_name) { nested_getter(nested_object_name) }
258
- define_method("build_#{reflection.single_name}") { |attributes = {}, nested_object = nil| build_nested_object(nested_object_name, attributes) }
262
+ define_method("build_#{reflection.single_name}") { |attributes = {}, nested_object = nil| build_nested_object(nested_object_name, attributes, nested_object) }
259
263
  define_method("existing_#{nested_object_name}") { existing_nested_objects(nested_object_name) }
260
264
  end
261
265
 
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "2.10.1"
2
+ VERSION = "2.10.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_attorney
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.1
4
+ version: 2.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler