object_attorney 2.2.12 → 2.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWYxODZiZjI4ZDA3ZmI3N2RlMzJjZDliMmQ1ZTRlYzg5NDkxZDZlNw==
4
+ YzdiMGM1YTg2ZmUyMDg4MzViMWJlYzE3ZDE5OGY4MTliZTY0N2Y0ZA==
5
5
  data.tar.gz: !binary |-
6
- YWIzZDY5MGUwN2NkYzliNjc0YmMxYTkyY2QyOTg2NzIwNzAzMjEyNQ==
6
+ NjU2Mjc5NjU4Y2VjOTM3YTEwMTA3MzgzYjQwNTY0YjNkOTRkOWM0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGQ3ZjVkMjc3MTMxNmEwNWFhMzI2MWQwNTc2NDEwYTM5MDZiZDljNWM5MDcx
10
- MDhiZDM1MjU5OThiMjM0YjAwOWExN2YwMWE0NjU3NDlmMzM2ZGUzMmI5Yjk2
11
- YmVhMzMyMDAxYzZmYzY5YjM5ZDEzNzAxNjNkZmM1YWUwMjUxMDA=
9
+ ZmNjOGRjNDRkMWMxMDlhMDM0ZmUzOTFhMDVlYTEwNzZjNDNiZTMwMWYwNDMz
10
+ NDQ3MjAzNDFjMTFkYjk1ZGFjMmM3YmI0MTYyOGZlNDA5ODE2ODhlMzJjZTll
11
+ M2IzNzMwYThhNzg2MTJkNjBhMjRiYzE2NWVjNDRiNjZhYWJhNjE=
12
12
  data.tar.gz: !binary |-
13
- NjhkMWYzYTFlNTg2NGQ4YzRmYjgzMWNmYjBiOTg0MGJlNjUzZGNkZjEwMjBj
14
- MGJiZTViMmYwMzViN2JkMzBlZDVkODA1MmVlZTBiNmI3YWVjMDJmZmNhMTA5
15
- ZmVlOWNjODc1YjcwMjk4OTYwN2JhOWZkMmE5NDFjZGRiYTljYjA=
13
+ ZjcwYTFmNDg5NTU0YWVkZTIxMzJiYmUzYTJiNTA2YzdhMTU2MjI3YzgyMTJl
14
+ YWU3ZDBlYTRkMGFhYzVhZTE4NmZkZTdkN2UwNjE5YjI3ZmUxZTMyMWQwZGZi
15
+ M2E2MWMxN2Y3ZjkxNjM2NDNiYWVhMjU1OGVjMWVlNzk4NTI0NzQ=
@@ -170,9 +170,9 @@ module ObjectAttorney
170
170
 
171
171
 
172
172
  if can_represented_object_build_nested?(reflection, nested_object_name)
173
- new_nested_object = build_from_represented_object(reflection, nested_object_name, attributes)
173
+ new_nested_object = build_from_represented_object(reflection, nested_object_name)
174
174
 
175
- new_nested_object = build_nested_custom_class_if_necessary(reflection, attributes, new_nested_object)
175
+ new_nested_object = assign_attributes_or_build_nested_object(reflection, attributes, new_nested_object)
176
176
  else
177
177
  new_nested_object = reflection.klass.new(attributes)
178
178
  end
@@ -182,29 +182,30 @@ module ObjectAttorney
182
182
  new_nested_object
183
183
  end
184
184
 
185
- def build_nested_custom_class_if_necessary(reflection, attributes, new_nested_object)
185
+ def assign_attributes_or_build_nested_object(reflection, attributes, new_nested_object)
186
186
  real_reflection_class = self.class.represented_object_reflect_on_association(reflection.name).try(:klass)
187
187
 
188
188
  if reflection.klass == real_reflection_class
189
- new_nested_object
189
+ new_nested_object.assign_attributes(attributes)
190
190
  else
191
191
  reflection.klass.respond_to?(:represents) ? reflection.klass.new(attributes, new_nested_object) : reflection.klass.new(attributes)
192
192
  end
193
193
  end
194
194
 
195
195
  def can_represented_object_build_nested?(reflection, nested_object_name)
196
- return nil if represented_object.blank?
196
+ return false if represented_object.blank?
197
197
 
198
198
  represented_object.respond_to?("build_#{nested_object_name}") || represented_object.send(nested_object_name).respond_to?(:build)
199
199
  end
200
200
 
201
- def build_from_represented_object(reflection, nested_object_name, attributes)
201
+ def build_from_represented_object(reflection, nested_object_name)
202
202
  build_method = "build_#{nested_object_name}"
203
203
 
204
204
  if represented_object.respond_to?(build_method)
205
- represented_object.send(build_method, attributes)
205
+ represented_object.send(build_method)
206
206
  else
207
- represented_object.send(nested_object_name).try(:build, attributes)
207
+ binding.pry
208
+ represented_object.send(nested_object_name).build
208
209
  end
209
210
  end
210
211
 
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "2.2.12"
2
+ VERSION = "2.2.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_attorney
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.12
4
+ version: 2.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves
@@ -157,3 +157,4 @@ test_files:
157
157
  - spec/support/models/comment.rb
158
158
  - spec/support/models/post.rb
159
159
  - spec/support/models/user.rb
160
+ has_rdoc: