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 +8 -8
- data/lib/object_attorney/nested_objects.rb +13 -7
- data/lib/object_attorney/version.rb +1 -1
- data/lib/object_attorney.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTk2Njg3MTNjZmFiOGMwYzc3MjQ4MDNjZmFmZmQ0YzcwYjA5YjdmMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWJiYTU4MjkzOTZhYTU0ODUxYjZmZjViNWE1YTBmNDlhMjA2NGQ2ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTNkZjU2MTUyNGMzNDk2ZWU0NGJhNDA3YjYyNmJiZDI4OTE5NGZhOWM0OWU0
|
10
|
+
YWUyMzNjY2Q2YTA1YTVhNTYyZThhZTZmNTVjYTU3YjQ5YzFjZDE0MmFmMDY2
|
11
|
+
NjVjNWQwYTQyMDFmNDIwZWJhYjFmZDkxNGZjMjMwNTJlNzU1Mjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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?
|
data/lib/object_attorney.rb
CHANGED
@@ -8,13 +8,15 @@ require 'active_record'
|
|
8
8
|
module ObjectAttorney
|
9
9
|
|
10
10
|
def initialize(attributes = {}, object = nil)
|
11
|
-
|
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?
|