slim_form_object 1.0.6 → 1.0.7
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 +7 -7
- data/lib/slim_form_object/form_helpers/extension_actionview.rb +0 -1
- data/lib/slim_form_object/helpers.rb +0 -2
- data/lib/slim_form_object/processing.rb +4 -10
- data/lib/slim_form_object/validator.rb +25 -11
- data/lib/slim_form_object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2aed3c55c37bbeb4b8f1fa75688bcbf70eb6f6f
|
4
|
+
data.tar.gz: cba65de38298064fcd60551819b2646b1d1b5026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f32e57070632547c8670b7a23f9d7016384411e059fbe954a8578436c9af18a0e7f0edcd407c2c17b3f431bd867a0c8c49cf206f45f5f23bd8fa062890d4707
|
7
|
+
data.tar.gz: d3038714911637b3f38a4eddc1daa7873481c2a2a23938f6472a5eba12f3c8d4b1b5b74c563b46eafcaa2e6bd74e27a965015d3a077eff77b93be63f313d1948
|
@@ -8,12 +8,12 @@ module SlimFormObject
|
|
8
8
|
@form_object = form_object
|
9
9
|
@params = form_object.params
|
10
10
|
@array_all_objects_for_save = form_object.array_all_objects_for_save
|
11
|
-
@not_save_this_model = form_object.not_save_this_model
|
11
|
+
# @not_save_this_model = form_object.not_save_this_model
|
12
12
|
@result_hash_updated_objects = {objects: [], nested_objects: {}}
|
13
13
|
end
|
14
14
|
|
15
15
|
def apply_parameters
|
16
|
-
filter_not_save_objects
|
16
|
+
# filter_not_save_objects
|
17
17
|
update_objects_attributes
|
18
18
|
make_nested_objects
|
19
19
|
|
@@ -22,11 +22,11 @@ module SlimFormObject
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def filter_not_save_objects
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
25
|
+
# def filter_not_save_objects
|
26
|
+
# array_all_objects_for_save.reject do |object|
|
27
|
+
# not_save_this_model.include?(object.class)
|
28
|
+
# end
|
29
|
+
# end
|
30
30
|
|
31
31
|
# STANDART OBJECTS
|
32
32
|
|
@@ -16,15 +16,10 @@ module SlimFormObject
|
|
16
16
|
end
|
17
17
|
alias_method :init_models, :init_single_models
|
18
18
|
|
19
|
-
def
|
19
|
+
def not_save_empty_object_for(*args)
|
20
|
+
args.each { |model| raise "#{model.to_s} - type is not a Class" if model.class != Class }
|
20
21
|
self.instance_eval do
|
21
|
-
define_method(:
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def force_save_if_all_attr_is_nil(*args)
|
26
|
-
self.instance_eval do
|
27
|
-
define_method(:force_save_if_all_attr_is_nil) { args }
|
22
|
+
define_method(:array_models_which_not_save_if_empty) { args }
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
@@ -101,8 +96,7 @@ module SlimFormObject
|
|
101
96
|
end
|
102
97
|
|
103
98
|
def check_array_settings_with_settings
|
104
|
-
define_singleton_method(:
|
105
|
-
define_singleton_method(:force_save_if_all_attr_is_nil) { [] } unless respond_to?(:force_save_if_all_attr_is_nil)
|
99
|
+
define_singleton_method(:array_models_which_not_save_if_empty) { [] } unless respond_to?(:array_models_which_not_save_if_empty)
|
106
100
|
end
|
107
101
|
|
108
102
|
end
|
@@ -2,22 +2,34 @@ module SlimFormObject
|
|
2
2
|
class Validator
|
3
3
|
include ::HelperMethods
|
4
4
|
|
5
|
-
attr_reader :form_object, :params, :hash_objects_for_save
|
5
|
+
attr_reader :form_object, :params, :hash_objects_for_save, :array_models_which_not_save_if_empty
|
6
6
|
|
7
7
|
def initialize(form_object)
|
8
|
-
@form_object
|
9
|
-
@params
|
10
|
-
@hash_objects_for_save
|
8
|
+
@form_object = form_object
|
9
|
+
@params = form_object.params
|
10
|
+
@hash_objects_for_save = form_object.hash_objects_for_save
|
11
|
+
@array_models_which_not_save_if_empty = form_object.array_models_which_not_save_if_empty
|
11
12
|
end
|
12
13
|
|
13
14
|
def validate_form_object
|
14
|
-
|
15
|
+
filter_models
|
16
|
+
validation_objects
|
17
|
+
validation_nested_objects
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid_model_for_save?(object)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
15
25
|
|
26
|
+
def validation_objects
|
16
27
|
hash_objects_for_save[:objects].each do |object|
|
17
|
-
next if all_attributes_is_nil?(object)
|
18
28
|
set_errors( snake(object.class), object.errors ) unless object.valid?
|
19
29
|
end
|
30
|
+
end
|
20
31
|
|
32
|
+
def validation_nested_objects
|
21
33
|
hash_objects_for_save[:nested_objects].keys.each do |snake_model_name|
|
22
34
|
hash_objects_for_save[:nested_objects][snake_model_name].each do |object|
|
23
35
|
set_errors( snake(object.class), object.errors ) unless object.valid?
|
@@ -25,15 +37,13 @@ module SlimFormObject
|
|
25
37
|
end
|
26
38
|
end
|
27
39
|
|
28
|
-
def
|
29
|
-
|
40
|
+
def filter_models
|
41
|
+
filter_nil_objects
|
30
42
|
end
|
31
43
|
|
32
|
-
private
|
33
|
-
|
34
44
|
def filter_nil_objects
|
35
45
|
hash_objects_for_save[:objects].reject! do |object|
|
36
|
-
|
46
|
+
!save_if_object_is_empty?(object)
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
@@ -44,6 +54,10 @@ module SlimFormObject
|
|
44
54
|
true
|
45
55
|
end
|
46
56
|
|
57
|
+
def save_if_object_is_empty?(object)
|
58
|
+
!(all_attributes_is_nil?(object) and array_models_which_not_save_if_empty.include?(object.class))
|
59
|
+
end
|
60
|
+
|
47
61
|
def set_errors(object_name, object_errors)
|
48
62
|
object_errors.each do |attribute, message|
|
49
63
|
form_object.errors.add(object_name, { attribute => message})
|
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: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- woodcrust
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|