object_attorney 2.2.6 → 2.2.7

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
- NjVkNTljNjRiNzdkYzJhMTU2N2ZkM2UzYTU2ZmFkZTQ5ODUxMmQ4Mw==
4
+ MTk2Njg3MTNjZmFiOGMwYzc3MjQ4MDNjZmFmZmQ0YzcwYjA5YjdmMQ==
5
5
  data.tar.gz: !binary |-
6
- MWQwZGRhNzkzNmYyMGY5ZGIxMWVhZDQ2ZDQ3ZGY0ZDQxYzViNzI0ZA==
6
+ MWJiYTU4MjkzOTZhYTU0ODUxYjZmZjViNWE1YTBmNDlhMjA2NGQ2ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- M2U0Mjc0NWIwYzVmZTUzNDA5Y2I5NGQ0MDg1NDQxNzE0MGMwNmNiNWJkYTc3
10
- NGViYzY3MmYxMmU3MzQ0MGE3MjBjYmM2ZjNkOWQ1OGViZjVjZTRhMDYzYTNj
11
- ODc5YTFjYjk5OGQxNzMzYjAxZTU3NjA3YWY3YmQ4OTYwNWZiYTA=
9
+ OTNkZjU2MTUyNGMzNDk2ZWU0NGJhNDA3YjYyNmJiZDI4OTE5NGZhOWM0OWU0
10
+ YWUyMzNjY2Q2YTA1YTVhNTYyZThhZTZmNTVjYTU3YjQ5YzFjZDE0MmFmMDY2
11
+ NjVjNWQwYTQyMDFmNDIwZWJhYjFmZDkxNGZjMjMwNTJlNzU1Mjk=
12
12
  data.tar.gz: !binary |-
13
- M2UwZmQ2MWJiZGMwNTc5NTIxZjQ0YjA5MzJlZjFkYTE2NjAzNGQyN2U1NjZh
14
- ZjJmZjE1MzAzNzkzNmY5OGMzODZiZDFlMDkzMjliOTUwYWQ1MDdiMTg5NDUx
15
- YTRjOTNmMDI4ODZhZTIwNGEwYjRhZDYxNjgyYTBhMTQ1MjM4YWM=
13
+ ZDA3NmVkZmY1ZjI0NWQ2OWYwMTg5MzFmYjIyN2UwMDM3NDY3NTRkODA5NWVm
14
+ OTlkMGZkNDhmNTJhMjNjYmMxNzhlYjU4NDg4MzhjYjAwNTQ3MDJhNDE2MzA3
15
+ NzE5YzI2N2MyMjcxNzY2NWQ3ZDA1Y2U1MzBlMWQwYmNiMTczYjI=
@@ -3,6 +3,12 @@ require "object_attorney/association_reflection"
3
3
  module ObjectAttorney
4
4
  module NestedObjects
5
5
 
6
+ def initialize_nested_attributes
7
+ self.class.reflect_on_all_associations.each do |reflection|
8
+ self.instance_variable_set("@#{reflection.name}_attribtues", {})
9
+ end
10
+ end
11
+
6
12
  def mark_for_destruction
7
13
  @marked_for_destruction = true
8
14
  end
@@ -218,7 +224,7 @@ module ObjectAttorney
218
224
  self.instance_variable_set("@#{nested_object_name}_reflection", reflection)
219
225
  self.instance_variable_set("@association_reflections", association_reflections | [reflection])
220
226
 
221
- define_nested_attributes_accessor(nested_object_name)
227
+ self.send(:attr_accessor, "#{nested_object_name}_attributes".to_sym)
222
228
 
223
229
  define_method(nested_object_name) { nested_getter(nested_object_name) }
224
230
  define_method("build_#{reflection.single_name}") { |attributes = {}, nested_object = nil| build_nested_object(nested_object_name, attributes) }
@@ -242,12 +248,12 @@ module ObjectAttorney
242
248
 
243
249
  private ############################### PRIVATE METHODS ###########################
244
250
 
245
- def define_nested_attributes_accessor(nested_object_name)
246
- self.send(:attr_writer, "#{nested_object_name}_attributes".to_sym)
247
- module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
248
- def #{nested_object_name}_attributes; @#{nested_object_name}_attributes ||= {}; end
249
- RUBY_EVAL
250
- end
251
+ # def define_nested_attributes_accessor(nested_object_name)
252
+ # self.send(:attr_writer, "#{nested_object_name}_attributes".to_sym)
253
+ # module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
254
+ # def #{nested_object_name}_attributes; @#{nested_object_name}_attributes ||= {}; end
255
+ # RUBY_EVAL
256
+ # end
251
257
 
252
258
  def define_nested_ids_accessor(nested_object_name, reflection)
253
259
  return nil unless reflection.has_many?
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "2.2.6"
2
+ VERSION = "2.2.7"
3
3
  end
@@ -8,13 +8,15 @@ require 'active_record'
8
8
  module ObjectAttorney
9
9
 
10
10
  def initialize(attributes = {}, object = nil)
11
- before_initialize(attributes)
11
+ initialize_nested_attributes
12
12
 
13
13
  if !attributes.is_a?(Hash) && object.blank?
14
14
  object = attributes
15
15
  attributes = nil
16
16
  end
17
17
 
18
+ before_initialize(attributes)
19
+
18
20
  attributes = {} if attributes.blank?
19
21
 
20
22
  @represented_object = object if object.present?
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.6
4
+ version: 2.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves