object_attorney 2.1.3 → 2.2.1
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/db/migrate/20131205114902_create_addresses.rb +1 -0
- data/lib/object_attorney/nested_objects.rb +26 -5
- data/lib/object_attorney/orm.rb +1 -5
- data/lib/object_attorney/orm_handlers/smooth_operator.rb +1 -5
- data/lib/object_attorney/version.rb +1 -1
- data/spec/object_attorney/post_with_comments_and_address_form_spec.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NDBmNWRmNjg0YjdkZjBmYjI1NjUyOTU4ZjIwOGVhMWI4ZWY3MzcyMQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
YjcyNTlkZmEyY2UzNWUyYjM4OGQzMDg2MTgzMmY3Mzg5YTJkZmFjYg==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
NDY0NTBlODhjNWI1OTc0ZDc2MmNmNjI2MmU2YWJmMjc4MTg2YmYxOWI1NDhm
|
|
10
|
+
MTUwYzdmMTVkMDQ4ZmU4NmJlYTdmZGRmNzBkMTQ2OWM1Mjc0ZjEyMWQ2NWYx
|
|
11
|
+
NTdkN2IwNGY3MGVlZTVkMGJiMzZmNjlmZDZiNDViZWJhNDg2OTE=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NjE0NDg4NDBhZGI3N2U2YWFlODFjYjg5ODU4OWY3NzE3ZWNlMzExMTYwYzUx
|
|
14
|
+
ZDFkMWNlNzNiM2VjNjE1MmM5NzI3OGNmMzk0YTZmOWEyYTJhMTZiZTRiMDQ5
|
|
15
|
+
MGI4NThlMTcwNDcwZGMxODQ5ZWE5MmQ3NTM0NzI3ODkxMDI2NzI=
|
|
@@ -49,12 +49,13 @@ module ObjectAttorney
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def validate_nested_objects
|
|
52
|
-
|
|
52
|
+
valid = nested_objects.map do |reflection, nested_object|
|
|
53
53
|
nested_object.marked_for_destruction? ? true : nested_object.valid?
|
|
54
54
|
end.all?
|
|
55
55
|
|
|
56
|
-
import_nested_objects_errors
|
|
57
|
-
|
|
56
|
+
import_nested_objects_errors unless valid
|
|
57
|
+
|
|
58
|
+
valid
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
def import_nested_objects_errors
|
|
@@ -86,7 +87,7 @@ module ObjectAttorney
|
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
def attributes_without_destroy(attributes)
|
|
89
|
-
return nil unless attributes.
|
|
90
|
+
return nil unless attributes.is_a?(Hash)
|
|
90
91
|
|
|
91
92
|
_attributes = attributes.dup
|
|
92
93
|
_attributes.delete("_destroy")
|
|
@@ -99,13 +100,33 @@ module ObjectAttorney
|
|
|
99
100
|
nested_instance_variable = self.instance_variable_get("@#{nested_object_name}")
|
|
100
101
|
|
|
101
102
|
if nested_instance_variable.nil?
|
|
102
|
-
|
|
103
|
+
reflection = self.class.reflect_on_association(nested_object_name)
|
|
104
|
+
|
|
105
|
+
nested_instance_variable = reflection.has_many? ? get_existing_and_new_nested_objects(nested_object_name) : get_existing_or_new_nested_object(nested_object_name)
|
|
106
|
+
|
|
103
107
|
self.instance_variable_set("@#{nested_object_name}", nested_instance_variable)
|
|
104
108
|
end
|
|
105
109
|
|
|
106
110
|
nested_instance_variable
|
|
107
111
|
end
|
|
108
112
|
|
|
113
|
+
def get_existing_or_new_nested_object(nested_object_name)
|
|
114
|
+
nested_object = send("existing_#{nested_object_name}")
|
|
115
|
+
attributes = send("#{nested_object_name}_attributes")
|
|
116
|
+
|
|
117
|
+
if nested_object.present?
|
|
118
|
+
return nested_object if (attributes["id"] || attributes[:id]).to_s != nested_object.id.to_s
|
|
119
|
+
|
|
120
|
+
nested_object.assign_attributes(attributes_without_destroy(attributes))
|
|
121
|
+
mark_for_destruction_if_necessary(nested_object, attributes)
|
|
122
|
+
else
|
|
123
|
+
nested_object = send("build_#{nested_object_name.to_s.singularize}", attributes_without_destroy(attributes))
|
|
124
|
+
mark_for_destruction_if_necessary(nested_object, attributes)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
nested_object
|
|
128
|
+
end
|
|
129
|
+
|
|
109
130
|
def get_existing_and_new_nested_objects(nested_object_name)
|
|
110
131
|
existing_and_new_nested_objects = []
|
|
111
132
|
|
data/lib/object_attorney/orm.rb
CHANGED
|
@@ -19,7 +19,7 @@ module ObjectAttorney
|
|
|
19
19
|
|
|
20
20
|
def save!(save_method = :save!)
|
|
21
21
|
before_save
|
|
22
|
-
save_result = valid? ?
|
|
22
|
+
save_result = valid? ? submit(save_method) : false
|
|
23
23
|
after_save if valid? && save_result
|
|
24
24
|
save_result
|
|
25
25
|
end
|
|
@@ -43,10 +43,6 @@ module ObjectAttorney
|
|
|
43
43
|
def before_save; end
|
|
44
44
|
def after_save; end
|
|
45
45
|
|
|
46
|
-
def save_after_validations(save_method)
|
|
47
|
-
submit(save_method)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
46
|
def submit(save_method)
|
|
51
47
|
save_result = save_or_destroy_nested_objects(save_method, :belongs_to)
|
|
52
48
|
save_result = save_or_destroy_represented_object(save_method) if save_result
|
|
@@ -9,7 +9,7 @@ module ObjectAttorney
|
|
|
9
9
|
|
|
10
10
|
def save!(options = {}, save_method = :save!)
|
|
11
11
|
before_save
|
|
12
|
-
save_result = valid? ?
|
|
12
|
+
save_result = valid? ? submit(save_method, options) : false
|
|
13
13
|
after_save if valid? && save_result
|
|
14
14
|
save_result
|
|
15
15
|
end
|
|
@@ -30,10 +30,6 @@ module ObjectAttorney
|
|
|
30
30
|
|
|
31
31
|
protected #################### PROTECTED METHODS DOWN BELOW ######################
|
|
32
32
|
|
|
33
|
-
def save_after_validations(save_method, options = {})
|
|
34
|
-
submit(save_method, options)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
33
|
def submit(save_method, options = {})
|
|
38
34
|
save_result = save_or_destroy_nested_objects(save_method, :belongs_to, options)
|
|
39
35
|
save_result = save_or_destroy_represented_object(save_method, options) if save_result
|
|
@@ -12,7 +12,8 @@ describe PostWithCommentsAndAddressForm do
|
|
|
12
12
|
"1" => { body: "" }
|
|
13
13
|
},
|
|
14
14
|
address_attributes: {
|
|
15
|
-
|
|
15
|
+
street: 'street',
|
|
16
|
+
city: 'city'
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -40,6 +41,7 @@ describe PostWithCommentsAndAddressForm do
|
|
|
40
41
|
address = Address.first
|
|
41
42
|
address.post_id.should == post.id
|
|
42
43
|
address.street.should == 'street'
|
|
44
|
+
address.city.should == 'city'
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
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.1
|
|
4
|
+
version: 2.2.1
|
|
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-01-
|
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|