slim_form_object 3.3.4 → 3.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slim_form_object/assign.rb +21 -15
- data/lib/slim_form_object/data_object.rb +2 -2
- data/lib/slim_form_object/extensions.rb +11 -0
- data/lib/slim_form_object/helpers.rb +13 -3
- data/lib/slim_form_object/saver.rb +13 -10
- data/lib/slim_form_object/version.rb +1 -1
- data/lib/slim_form_object.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e4f0412c8cb4946eff0db2874dc18f1eb89a5963fa37e93bebf5f6df43e6325
|
4
|
+
data.tar.gz: 0fcdf0fe63e50fce431424ad491d777b82ff526322bd0cd477e8410f5013d5cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0196290af54aa19b2bd8877aaf4fa65bc8e7457395a1591dc3b96c62985f98e35be934509984a7e6f095d8c9785e6f72efb61d2471aadd49bb22cb7815e7988d'
|
7
|
+
data.tar.gz: 04f5c24113803d60c5ecf5c29ce3ad10a3abdf39450902fefcdbf83ac1fe76c4970b5e272f218f48e316c4cb3e7c4fe994f8e7af98962efdf2c8475efc4ebb4d
|
@@ -20,11 +20,14 @@ module SlimFormObject
|
|
20
20
|
parse_params(params)
|
21
21
|
@data_objects_arr = make_data_objects(data_for_assign)
|
22
22
|
clean_data_objects_arr(data_objects_arr)
|
23
|
+
|
23
24
|
associate_all_objects(data_objects_arr)
|
24
25
|
|
25
26
|
data_objects_arr
|
26
27
|
end
|
27
28
|
|
29
|
+
|
30
|
+
|
28
31
|
private
|
29
32
|
|
30
33
|
# data_for_assign format
|
@@ -96,32 +99,35 @@ module SlimFormObject
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
|
-
def
|
100
|
-
objects
|
101
|
-
|
102
|
-
|
103
|
-
objects.each do |data_object_2|
|
104
|
-
data_object_1.associate_with(data_object_2.object)
|
105
|
-
end
|
102
|
+
def clean_data_objects_arr(objects)
|
103
|
+
objects.select! do |data_object|
|
104
|
+
clean_data_objects_arr(data_object.nested)
|
105
|
+
validator.allow_object_processing?(data_object)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
# ASSOCIATE
|
109
110
|
def associate_all_objects(objects)
|
110
|
-
|
111
|
+
associate_nested_objects(objects)
|
112
|
+
associate_parents_with_nested_objects(objects)
|
113
|
+
end
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
+
def associate_nested_objects(data_objects)
|
116
|
+
cloned_objects = Array.new(data_objects)
|
117
|
+
while data_object_1 = cloned_objects.delete(cloned_objects[0])
|
118
|
+
associate_nested_objects(data_object_1.nested)
|
119
|
+
cloned_objects.each do |data_object_2|
|
120
|
+
data_object_1.associate_with(data_object_2.object)
|
115
121
|
end
|
116
122
|
end
|
117
123
|
end
|
118
124
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
validator.allow_object_processing?(data_object)
|
125
|
+
def associate_parents_with_nested_objects(data_objects)
|
126
|
+
iterate_parents_with_nested_objects(data_objects) do |data_object, nested_data_object|
|
127
|
+
data_object.associate_with(nested_data_object.object)
|
123
128
|
end
|
124
129
|
end
|
130
|
+
# END ASSOCIATE
|
125
131
|
|
126
132
|
end
|
127
133
|
end
|
@@ -15,8 +15,8 @@ module SlimFormObject
|
|
15
15
|
assign_attributes!
|
16
16
|
end
|
17
17
|
|
18
|
-
def associate_with(other_object,
|
19
|
-
return object if (
|
18
|
+
def associate_with(other_object, force: false)
|
19
|
+
return object if ( force and (!object.new_record? and !other_object.new_record?) )
|
20
20
|
|
21
21
|
to_bind_models(object, other_object)
|
22
22
|
end
|
@@ -4,8 +4,8 @@ module HelperMethods
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def make_constant_name(snake_model_name, base_module=nil)
|
7
|
-
|
8
|
-
|
7
|
+
pref = base_module ? (base_module.to_s + '::') : ''
|
8
|
+
pref + snake_model_name.to_s.split('_').map(&:capitalize).join
|
9
9
|
end
|
10
10
|
|
11
11
|
def get_class_of(snake_model_name, base_module=nil)
|
@@ -29,7 +29,7 @@ module HelperMethods
|
|
29
29
|
def assignment_to_each_other(object_1, object_2)
|
30
30
|
type, method_name = get_type_and_name_of_association(object_1.class, object_2.class)
|
31
31
|
|
32
|
-
if
|
32
|
+
if type == :belongs_to or type == :has_one
|
33
33
|
object_1.send( "#{method_name.to_s}=", object_2 )
|
34
34
|
elsif type == :has_many or type == :has_and_belongs_to_many
|
35
35
|
object_1.method(method_name).call << object_2
|
@@ -83,4 +83,14 @@ module HelperMethods
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
def iterate_parents_with_nested_objects(data_objects, &block)
|
87
|
+
data_objects.each do |data_object|
|
88
|
+
iterate_parents_with_nested_objects(data_object.nested, &block)
|
89
|
+
data_object.nested.each do |nested_data_object|
|
90
|
+
block.call(data_object, nested_data_object) if block
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
86
95
|
end
|
96
|
+
|
@@ -4,8 +4,6 @@ module SlimFormObject
|
|
4
4
|
|
5
5
|
attr_reader :form_object, :params, :validator, :data_objects_arr
|
6
6
|
|
7
|
-
STAGE_3 = 3
|
8
|
-
|
9
7
|
def initialize(form_object)
|
10
8
|
@form_object = form_object
|
11
9
|
@params = form_object.params
|
@@ -47,6 +45,7 @@ module SlimFormObject
|
|
47
45
|
stage_1(data_objects_arr)
|
48
46
|
stage_2(data_objects_arr)
|
49
47
|
stage_3(data_objects_arr)
|
48
|
+
stage_4(data_objects_arr)
|
50
49
|
form_object.after_save_form_block.call(form_object)
|
51
50
|
end
|
52
51
|
end
|
@@ -61,7 +60,7 @@ module SlimFormObject
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
64
|
-
# save all objects
|
63
|
+
# save all nested objects
|
65
64
|
def stage_2(objects)
|
66
65
|
objects.each do |data_object|
|
67
66
|
stage_2(data_object.nested)
|
@@ -79,12 +78,17 @@ module SlimFormObject
|
|
79
78
|
end
|
80
79
|
|
81
80
|
def associate_and_save_objects(data_objects)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
data_objects.iterate_with_each_pair do |data_object_1, data_object_2|
|
82
|
+
obj = data_object_1.associate_with(data_object_2.object, force: true)
|
83
|
+
save_object(obj)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# association per parent with all nested objects with FORCE TRUE option
|
88
|
+
def stage_4(objects)
|
89
|
+
iterate_parents_with_nested_objects(objects) do |data_object, nested_data_object|
|
90
|
+
obj = data_object.associate_with(nested_data_object.object, force: true)
|
91
|
+
save_object(obj)
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
@@ -93,6 +97,5 @@ module SlimFormObject
|
|
93
97
|
object_of_model.save!
|
94
98
|
end
|
95
99
|
end
|
96
|
-
|
97
100
|
end
|
98
101
|
end
|
data/lib/slim_form_object.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim_form_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nerzh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/slim_form_object.rb
|
150
150
|
- lib/slim_form_object/assign.rb
|
151
151
|
- lib/slim_form_object/data_object.rb
|
152
|
+
- lib/slim_form_object/extensions.rb
|
152
153
|
- lib/slim_form_object/form_helpers/extension_actionview.rb
|
153
154
|
- lib/slim_form_object/helpers.rb
|
154
155
|
- lib/slim_form_object/processing.rb
|