servactory 2.6.3 → 2.7.0
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 +4 -4
- data/config/locales/en.yml +12 -0
- data/config/locales/ru.yml +12 -0
- data/lib/servactory/actions/dsl.rb +2 -2
- data/lib/servactory/actions/tools/runner.rb +1 -1
- data/lib/servactory/configuration/setup.rb +3 -3
- data/lib/servactory/context/callable.rb +7 -7
- data/lib/servactory/context/workspace/inputs.rb +2 -2
- data/lib/servactory/context/workspace/internals.rb +3 -3
- data/lib/servactory/context/workspace/outputs.rb +3 -3
- data/lib/servactory/context/workspace.rb +19 -19
- data/lib/servactory/info/dsl.rb +3 -3
- data/lib/servactory/inputs/input.rb +5 -5
- data/lib/servactory/inputs/tools/validation.rb +7 -7
- data/lib/servactory/inputs/validations/required.rb +1 -1
- data/lib/servactory/internals/internal.rb +5 -5
- data/lib/servactory/maintenance/attributes/option.rb +13 -13
- data/lib/servactory/maintenance/attributes/tools/validation.rb +5 -5
- data/lib/servactory/maintenance/attributes/translator/inclusion.rb +2 -2
- data/lib/servactory/maintenance/attributes/translator/must.rb +8 -8
- data/lib/servactory/maintenance/attributes/translator/type.rb +12 -12
- data/lib/servactory/maintenance/attributes/validations/inclusion.rb +1 -1
- data/lib/servactory/maintenance/attributes/validations/must.rb +7 -7
- data/lib/servactory/maintenance/attributes/validations/type.rb +1 -1
- data/lib/servactory/maintenance/validations/object_schema.rb +11 -11
- data/lib/servactory/outputs/output.rb +5 -5
- data/lib/servactory/result.rb +4 -4
- data/lib/servactory/test_kit/result.rb +2 -2
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +1 -1
- data/lib/servactory/tool_kit/dynamic_options/consists_of.rb +14 -13
- data/lib/servactory/tool_kit/dynamic_options/format.rb +11 -8
- data/lib/servactory/tool_kit/dynamic_options/max.rb +12 -9
- data/lib/servactory/tool_kit/dynamic_options/min.rb +12 -9
- data/lib/servactory/tool_kit/dynamic_options/multiple_of.rb +103 -0
- data/lib/servactory/tool_kit/dynamic_options/must.rb +16 -13
- data/lib/servactory/version.rb +2 -2
- metadata +5 -4
@@ -8,7 +8,7 @@ module Servactory
|
|
8
8
|
def self.check(context:, attribute:, value:, check_key:, **)
|
9
9
|
return unless should_be_checked_for?(attribute, value, check_key)
|
10
10
|
|
11
|
-
new(context
|
11
|
+
new(context:, attribute:, value:).check
|
12
12
|
end
|
13
13
|
|
14
14
|
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -8,7 +8,7 @@ module Servactory
|
|
8
8
|
def self.check(context:, attribute:, value:, check_key:, check_options:)
|
9
9
|
return unless should_be_checked_for?(attribute, check_key)
|
10
10
|
|
11
|
-
new(context
|
11
|
+
new(context:, attribute:, value:, check_options:).check
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.should_be_checked_for?(attribute, check_key)
|
@@ -64,23 +64,23 @@ module Servactory
|
|
64
64
|
|
65
65
|
def add_error_with(message, code, reason)
|
66
66
|
add_error(
|
67
|
-
message
|
67
|
+
message:,
|
68
68
|
service: @context.send(:servactory_service_info),
|
69
69
|
**Servactory::Utils.fetch_hash_with_desired_attribute(@attribute),
|
70
70
|
value: @value,
|
71
|
-
code
|
72
|
-
reason:
|
71
|
+
code:,
|
72
|
+
reason:
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
76
|
def add_syntax_error_with(message, code, exception_message)
|
77
77
|
add_error(
|
78
|
-
message
|
78
|
+
message:,
|
79
79
|
service: @context.send(:servactory_service_info),
|
80
80
|
**Servactory::Utils.fetch_hash_with_desired_attribute(@attribute),
|
81
81
|
value: @value,
|
82
|
-
code
|
83
|
-
exception_message:
|
82
|
+
code:,
|
83
|
+
exception_message:
|
84
84
|
)
|
85
85
|
end
|
86
86
|
end
|
@@ -8,7 +8,7 @@ module Servactory
|
|
8
8
|
def self.check(context:, attribute:, value:, check_key:, **)
|
9
9
|
return unless should_be_checked_for?(attribute, value, check_key)
|
10
10
|
|
11
|
-
new(context
|
11
|
+
new(context:, attribute:, value:).check
|
12
12
|
end
|
13
13
|
|
14
14
|
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -49,10 +49,10 @@ module Servactory
|
|
49
49
|
)
|
50
50
|
else
|
51
51
|
is_success = validate_with(
|
52
|
-
object
|
53
|
-
schema_key
|
54
|
-
schema_value
|
55
|
-
attribute_type
|
52
|
+
object:,
|
53
|
+
schema_key:,
|
54
|
+
schema_value:,
|
55
|
+
attribute_type:,
|
56
56
|
attribute_required: schema_value.fetch(:required, true)
|
57
57
|
)
|
58
58
|
|
@@ -69,16 +69,16 @@ module Servactory
|
|
69
69
|
|
70
70
|
def validate_with(object:, schema_key:, schema_value:, attribute_type:, attribute_required:) # rubocop:disable Metrics/MethodLength
|
71
71
|
unless should_be_checked_for?(
|
72
|
-
object
|
73
|
-
schema_key
|
74
|
-
schema_value
|
72
|
+
object:,
|
73
|
+
schema_key:,
|
74
|
+
schema_value:,
|
75
75
|
required: attribute_required
|
76
76
|
) # do
|
77
77
|
return true
|
78
78
|
end
|
79
79
|
|
80
80
|
value = object.fetch(schema_key, nil)
|
81
|
-
prepared_value = prepare_value_from(schema_value
|
81
|
+
prepared_value = prepare_value_from(schema_value:, value:, required: attribute_required)
|
82
82
|
|
83
83
|
Array(attribute_type).any? { |type| prepared_value.is_a?(type) }
|
84
84
|
end
|
@@ -105,9 +105,9 @@ module Servactory
|
|
105
105
|
|
106
106
|
def add_error(key_name:, expected_type:, given_type:)
|
107
107
|
@errors << {
|
108
|
-
key_name
|
109
|
-
expected_type
|
110
|
-
given_type:
|
108
|
+
key_name:,
|
109
|
+
expected_type:,
|
110
|
+
given_type:
|
111
111
|
}
|
112
112
|
end
|
113
113
|
end
|
@@ -36,11 +36,11 @@ module Servactory
|
|
36
36
|
@hash_mode_class_names = hash_mode_class_names
|
37
37
|
@option_helpers = option_helpers
|
38
38
|
|
39
|
-
register_options(helpers
|
39
|
+
register_options(helpers:, options:)
|
40
40
|
end
|
41
41
|
|
42
42
|
def method_missing(name, *args, &block)
|
43
|
-
option = @collection_of_options.find_by(name:
|
43
|
+
option = @collection_of_options.find_by(name:)
|
44
44
|
|
45
45
|
return super if option.nil?
|
46
46
|
|
@@ -54,13 +54,13 @@ module Servactory
|
|
54
54
|
def register_options(helpers:, options:) # rubocop:disable Metrics/MethodLength
|
55
55
|
advanced_helpers = options.except(*Servactory::Maintenance::Attributes::Options::Registrar::RESERVED_OPTIONS)
|
56
56
|
|
57
|
-
options = apply_helpers_for_options(helpers
|
58
|
-
options = apply_helpers_for_options(helpers: advanced_helpers, options:
|
57
|
+
options = apply_helpers_for_options(helpers:, options:) if helpers.present?
|
58
|
+
options = apply_helpers_for_options(helpers: advanced_helpers, options:) if advanced_helpers.present?
|
59
59
|
|
60
60
|
options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
|
61
61
|
attribute: self,
|
62
62
|
hash_mode_class_names: @hash_mode_class_names,
|
63
|
-
options
|
63
|
+
options:,
|
64
64
|
features: {
|
65
65
|
types: true,
|
66
66
|
hash: true,
|
data/lib/servactory/result.rb
CHANGED
@@ -28,11 +28,11 @@ module Servactory
|
|
28
28
|
############################################################################
|
29
29
|
|
30
30
|
def self.success_for(context:)
|
31
|
-
new(context:
|
31
|
+
new(context:).send(:as_success)
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.failure_for(context:, exception:)
|
35
|
-
new(context
|
35
|
+
new(context:, exception:).send(:as_failure)
|
36
36
|
end
|
37
37
|
|
38
38
|
def initialize(context:, exception: nil)
|
@@ -45,13 +45,13 @@ module Servactory
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def on_success
|
48
|
-
yield(outputs:
|
48
|
+
yield(outputs:) if success?
|
49
49
|
|
50
50
|
self
|
51
51
|
end
|
52
52
|
|
53
53
|
def on_failure(type = :all)
|
54
|
-
yield(outputs
|
54
|
+
yield(outputs:, exception: @exception) if failure? && [:all, @exception&.type].include?(type)
|
55
55
|
|
56
56
|
self
|
57
57
|
end
|
@@ -6,13 +6,13 @@ module Servactory
|
|
6
6
|
def self.as_success(attributes = {})
|
7
7
|
context = new(attributes)
|
8
8
|
|
9
|
-
Servactory::Result.success_for(context:
|
9
|
+
Servactory::Result.success_for(context:)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.as_failure(attributes = {}, exception: nil)
|
13
13
|
context = new(attributes)
|
14
14
|
|
15
|
-
Servactory::Result.failure_for(context
|
15
|
+
Servactory::Result.failure_for(context:, exception:)
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(attributes = {})
|
@@ -15,15 +15,15 @@ module Servactory
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def condition_for_input_with(input:, value:, option:)
|
18
|
-
common_condition_with(attribute: input, value
|
18
|
+
common_condition_with(attribute: input, value:, option:)
|
19
19
|
end
|
20
20
|
|
21
21
|
def condition_for_internal_with(internal:, value:, option:)
|
22
|
-
common_condition_with(attribute: internal, value
|
22
|
+
common_condition_with(attribute: internal, value:, option:)
|
23
23
|
end
|
24
24
|
|
25
25
|
def condition_for_output_with(output:, value:, option:)
|
26
|
-
common_condition_with(attribute: output, value
|
26
|
+
common_condition_with(attribute: output, value:, option:)
|
27
27
|
end
|
28
28
|
|
29
29
|
def common_condition_with(attribute:, value:, option:)
|
@@ -32,15 +32,13 @@ module Servactory
|
|
32
32
|
|
33
33
|
values = value.respond_to?(:flatten) ? value&.flatten : value
|
34
34
|
|
35
|
-
validate_for!(attribute
|
35
|
+
validate_for!(attribute:, values:, option:)
|
36
36
|
end
|
37
37
|
|
38
38
|
def validate_for!(attribute:, values:, option:)
|
39
39
|
consists_of_types = Array(option.value)
|
40
40
|
|
41
|
-
if fails_presence_validation?(attribute
|
42
|
-
return [false, :required]
|
43
|
-
end
|
41
|
+
return [false, :required] if fails_presence_validation?(attribute:, values:, consists_of_types:)
|
44
42
|
|
45
43
|
return true if values.blank? && attribute.input? && attribute.optional?
|
46
44
|
|
@@ -65,7 +63,7 @@ module Servactory
|
|
65
63
|
|
66
64
|
########################################################################
|
67
65
|
|
68
|
-
def message_for_input_with(service:, input:, value:, option_value:, reason:, **)
|
66
|
+
def message_for_input_with(service:, input:, value:, option_name:, option_value:, reason:, **)
|
69
67
|
i18n_key = "inputs.validations.must.dynamic_options.consists_of"
|
70
68
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
71
69
|
|
@@ -73,12 +71,13 @@ module Servactory
|
|
73
71
|
i18n_key,
|
74
72
|
service_class_name: service.class_name,
|
75
73
|
input_name: input.name,
|
74
|
+
option_name:,
|
76
75
|
expected_type: Array(option_value).uniq.join(", "),
|
77
|
-
given_type: given_type_for(values: value, option_value:
|
76
|
+
given_type: given_type_for(values: value, option_value:)
|
78
77
|
)
|
79
78
|
end
|
80
79
|
|
81
|
-
def message_for_internal_with(service:, internal:, value:, option_value:, reason:, **)
|
80
|
+
def message_for_internal_with(service:, internal:, value:, option_name:, option_value:, reason:, **)
|
82
81
|
i18n_key = "internals.validations.must.dynamic_options.consists_of"
|
83
82
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
84
83
|
|
@@ -86,12 +85,13 @@ module Servactory
|
|
86
85
|
i18n_key,
|
87
86
|
service_class_name: service.class_name,
|
88
87
|
internal_name: internal.name,
|
88
|
+
option_name:,
|
89
89
|
expected_type: Array(option_value).uniq.join(", "),
|
90
|
-
given_type: given_type_for(values: value, option_value:
|
90
|
+
given_type: given_type_for(values: value, option_value:)
|
91
91
|
)
|
92
92
|
end
|
93
93
|
|
94
|
-
def message_for_output_with(service:, output:, value:, option_value:, reason:, **)
|
94
|
+
def message_for_output_with(service:, output:, value:, option_name:, option_value:, reason:, **)
|
95
95
|
i18n_key = "outputs.validations.must.dynamic_options.consists_of"
|
96
96
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
97
97
|
|
@@ -99,8 +99,9 @@ module Servactory
|
|
99
99
|
i18n_key,
|
100
100
|
service_class_name: service.class_name,
|
101
101
|
output_name: output.name,
|
102
|
+
option_name:,
|
102
103
|
expected_type: Array(option_value).uniq.join(", "),
|
103
|
-
given_type: given_type_for(values: value, option_value:
|
104
|
+
given_type: given_type_for(values: value, option_value:)
|
104
105
|
)
|
105
106
|
end
|
106
107
|
|
@@ -88,7 +88,7 @@ module Servactory
|
|
88
88
|
|
89
89
|
return [false, :unknown] unless @formats.key?(option_value)
|
90
90
|
|
91
|
-
attribute = Utils.define_attribute_with(input
|
91
|
+
attribute = Utils.define_attribute_with(input:, internal:, output:)
|
92
92
|
|
93
93
|
if value.blank? &&
|
94
94
|
(
|
@@ -107,44 +107,47 @@ module Servactory
|
|
107
107
|
|
108
108
|
return [false, :wrong_pattern] if format_pattern.present? && !value.match?(Regexp.compile(format_pattern))
|
109
109
|
|
110
|
-
option.properties.fetch(:validator, format_options.fetch(:validator)).call(value:
|
110
|
+
option.properties.fetch(:validator, format_options.fetch(:validator)).call(value:)
|
111
111
|
end
|
112
112
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
113
113
|
|
114
114
|
########################################################################
|
115
115
|
|
116
|
-
def message_for_input_with(service:, input:, value:, option_value:, reason:, **)
|
116
|
+
def message_for_input_with(service:, input:, value:, option_name:, option_value:, reason:, **)
|
117
117
|
i18n_key = "inputs.validations.must.dynamic_options.format"
|
118
118
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
119
119
|
|
120
120
|
service.translate(
|
121
121
|
i18n_key,
|
122
122
|
input_name: input.name,
|
123
|
-
value
|
123
|
+
value:,
|
124
|
+
option_name:,
|
124
125
|
format_name: option_value.present? ? option_value : option_value.inspect
|
125
126
|
)
|
126
127
|
end
|
127
128
|
|
128
|
-
def message_for_internal_with(service:, internal:, value:, option_value:, reason:, **)
|
129
|
+
def message_for_internal_with(service:, internal:, value:, option_name:, option_value:, reason:, **)
|
129
130
|
i18n_key = "internals.validations.must.dynamic_options.format"
|
130
131
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
131
132
|
|
132
133
|
service.translate(
|
133
134
|
i18n_key,
|
134
135
|
internal_name: internal.name,
|
135
|
-
value
|
136
|
+
value:,
|
137
|
+
option_name:,
|
136
138
|
format_name: option_value.present? ? option_value : option_value.inspect
|
137
139
|
)
|
138
140
|
end
|
139
141
|
|
140
|
-
def message_for_output_with(service:, output:, value:, option_value:, reason:, **)
|
142
|
+
def message_for_output_with(service:, output:, value:, option_name:, option_value:, reason:, **)
|
141
143
|
i18n_key = "outputs.validations.must.dynamic_options.format"
|
142
144
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
143
145
|
|
144
146
|
service.translate(
|
145
147
|
i18n_key,
|
146
148
|
output_name: output.name,
|
147
|
-
value
|
149
|
+
value:,
|
150
|
+
option_name:,
|
148
151
|
format_name: option_value.present? ? option_value : option_value.inspect
|
149
152
|
)
|
150
153
|
end
|
@@ -33,30 +33,33 @@ module Servactory
|
|
33
33
|
|
34
34
|
########################################################################
|
35
35
|
|
36
|
-
def message_for_input_with(service:, input:, value:, option_value:, **)
|
36
|
+
def message_for_input_with(service:, input:, value:, option_name:, option_value:, **)
|
37
37
|
service.translate(
|
38
38
|
"inputs.validations.must.dynamic_options.max.default",
|
39
39
|
input_name: input.name,
|
40
|
-
value
|
41
|
-
|
40
|
+
value:,
|
41
|
+
option_name:,
|
42
|
+
option_value:
|
42
43
|
)
|
43
44
|
end
|
44
45
|
|
45
|
-
def message_for_internal_with(service:, internal:, value:, option_value:, **)
|
46
|
+
def message_for_internal_with(service:, internal:, value:, option_name:, option_value:, **)
|
46
47
|
service.translate(
|
47
48
|
"internals.validations.must.dynamic_options.max.default",
|
48
49
|
internal_name: internal.name,
|
49
|
-
value
|
50
|
-
|
50
|
+
value:,
|
51
|
+
option_name:,
|
52
|
+
option_value:
|
51
53
|
)
|
52
54
|
end
|
53
55
|
|
54
|
-
def message_for_output_with(service:, output:, value:, option_value:, **)
|
56
|
+
def message_for_output_with(service:, output:, value:, option_name:, option_value:, **)
|
55
57
|
service.translate(
|
56
58
|
"outputs.validations.must.dynamic_options.max.default",
|
57
59
|
output_name: output.name,
|
58
|
-
value
|
59
|
-
|
60
|
+
value:,
|
61
|
+
option_name:,
|
62
|
+
option_value:
|
60
63
|
)
|
61
64
|
end
|
62
65
|
end
|
@@ -33,30 +33,33 @@ module Servactory
|
|
33
33
|
|
34
34
|
########################################################################
|
35
35
|
|
36
|
-
def message_for_input_with(service:, input:, value:, option_value:, **)
|
36
|
+
def message_for_input_with(service:, input:, value:, option_name:, option_value:, **)
|
37
37
|
service.translate(
|
38
38
|
"inputs.validations.must.dynamic_options.min.default",
|
39
39
|
input_name: input.name,
|
40
|
-
value
|
41
|
-
|
40
|
+
value:,
|
41
|
+
option_name:,
|
42
|
+
option_value:
|
42
43
|
)
|
43
44
|
end
|
44
45
|
|
45
|
-
def message_for_internal_with(service:, internal:, value:, option_value:, **)
|
46
|
+
def message_for_internal_with(service:, internal:, value:, option_name:, option_value:, **)
|
46
47
|
service.translate(
|
47
48
|
"internals.validations.must.dynamic_options.min.default",
|
48
49
|
internal_name: internal.name,
|
49
|
-
value
|
50
|
-
|
50
|
+
value:,
|
51
|
+
option_name:,
|
52
|
+
option_value:
|
51
53
|
)
|
52
54
|
end
|
53
55
|
|
54
|
-
def message_for_output_with(service:, output:, value:, option_value:, **)
|
56
|
+
def message_for_output_with(service:, output:, value:, option_name:, option_value:, **)
|
55
57
|
service.translate(
|
56
58
|
"outputs.validations.must.dynamic_options.min.default",
|
57
59
|
output_name: output.name,
|
58
|
-
value
|
59
|
-
|
60
|
+
value:,
|
61
|
+
option_name:,
|
62
|
+
option_value:
|
60
63
|
)
|
61
64
|
end
|
62
65
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module ToolKit
|
5
|
+
module DynamicOptions
|
6
|
+
class MultipleOf < Must
|
7
|
+
def self.use(option_name = :multiple_of)
|
8
|
+
new(option_name).must(:be_multiple_of)
|
9
|
+
end
|
10
|
+
|
11
|
+
def condition_for_input_with(...)
|
12
|
+
common_condition_with(...)
|
13
|
+
end
|
14
|
+
|
15
|
+
def condition_for_internal_with(...)
|
16
|
+
common_condition_with(...)
|
17
|
+
end
|
18
|
+
|
19
|
+
def condition_for_output_with(...)
|
20
|
+
common_condition_with(...)
|
21
|
+
end
|
22
|
+
|
23
|
+
def common_condition_with(value:, option:, **)
|
24
|
+
case value
|
25
|
+
when Integer, Float, Rational, BigDecimal
|
26
|
+
return false if option.value.blank?
|
27
|
+
return false unless [Numeric, Float, Rational, BigDecimal].any? { |c| option.value.is_a?(c) }
|
28
|
+
return false if option.value.zero?
|
29
|
+
|
30
|
+
(value % option.value).zero?
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
########################################################################
|
37
|
+
|
38
|
+
def message_for_input_with(service:, input:, value:, option_name:, option_value:, **) # rubocop:disable Metrics/MethodLength
|
39
|
+
i18n_key = "inputs.validations.must.dynamic_options.multiple_of"
|
40
|
+
|
41
|
+
i18n_key += if option_value.blank?
|
42
|
+
".blank"
|
43
|
+
elsif [Numeric, Float, Rational, BigDecimal].any? { |c| option_value.is_a?(c) } &&
|
44
|
+
option_value.zero?
|
45
|
+
".divided_by_0"
|
46
|
+
else
|
47
|
+
".default"
|
48
|
+
end
|
49
|
+
|
50
|
+
service.translate(
|
51
|
+
i18n_key,
|
52
|
+
input_name: input.name,
|
53
|
+
value:,
|
54
|
+
option_name:,
|
55
|
+
option_value: option_value.inspect
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def message_for_internal_with(service:, internal:, value:, option_name:, option_value:, **) # rubocop:disable Metrics/MethodLength
|
60
|
+
i18n_key = "internals.validations.must.dynamic_options.multiple_of"
|
61
|
+
|
62
|
+
i18n_key += if option_value.blank?
|
63
|
+
".blank"
|
64
|
+
elsif [Numeric, Float, Rational, BigDecimal].any? { |c| option_value.is_a?(c) } &&
|
65
|
+
option_value.zero?
|
66
|
+
".divided_by_0"
|
67
|
+
else
|
68
|
+
".default"
|
69
|
+
end
|
70
|
+
|
71
|
+
service.translate(
|
72
|
+
i18n_key,
|
73
|
+
internal_name: internal.name,
|
74
|
+
value:,
|
75
|
+
option_name:,
|
76
|
+
option_value: option_value.inspect
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def message_for_output_with(service:, output:, value:, option_name:, option_value:, **) # rubocop:disable Metrics/MethodLength
|
81
|
+
i18n_key = "outputs.validations.must.dynamic_options.multiple_of"
|
82
|
+
|
83
|
+
i18n_key += if option_value.blank?
|
84
|
+
".blank"
|
85
|
+
elsif [Numeric, Float, Rational, BigDecimal].any? { |c| option_value.is_a?(c) } &&
|
86
|
+
option_value.zero?
|
87
|
+
".divided_by_0"
|
88
|
+
else
|
89
|
+
".default"
|
90
|
+
end
|
91
|
+
|
92
|
+
service.translate(
|
93
|
+
i18n_key,
|
94
|
+
output_name: output.name,
|
95
|
+
value:,
|
96
|
+
option_name:,
|
97
|
+
option_value: option_value.inspect
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -5,11 +5,14 @@ module Servactory
|
|
5
5
|
module DynamicOptions
|
6
6
|
class Must
|
7
7
|
class WorkOption
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :name,
|
9
|
+
:value,
|
9
10
|
:message,
|
10
11
|
:properties
|
11
12
|
|
12
|
-
def initialize(data, body_key:, body_fallback:)
|
13
|
+
def initialize(name, data, body_key:, body_fallback:)
|
14
|
+
@name = name
|
15
|
+
|
13
16
|
@value =
|
14
17
|
if data.is_a?(Hash) && data.key?(body_key)
|
15
18
|
data.delete(body_key)
|
@@ -37,7 +40,7 @@ module Servactory
|
|
37
40
|
|
38
41
|
def equivalent_with(name)
|
39
42
|
lambda do |data|
|
40
|
-
option = WorkOption.new(data, body_key: @body_key, body_fallback: @body_fallback)
|
43
|
+
option = WorkOption.new(@option_name, data, body_key: @body_key, body_fallback: @body_fallback)
|
41
44
|
|
42
45
|
{
|
43
46
|
must: {
|
@@ -59,11 +62,11 @@ module Servactory
|
|
59
62
|
def must_content_value_with(option)
|
60
63
|
lambda do |value:, input: nil, internal: nil, output: nil|
|
61
64
|
if input.present? && input.input?
|
62
|
-
condition_for_input_with(input
|
65
|
+
condition_for_input_with(input:, value:, option:)
|
63
66
|
elsif internal.present? && internal.internal?
|
64
|
-
condition_for_internal_with(internal
|
67
|
+
condition_for_internal_with(internal:, value:, option:)
|
65
68
|
elsif output.present? && output.output?
|
66
|
-
condition_for_output_with(output
|
69
|
+
condition_for_output_with(output:, value:, option:)
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
@@ -74,25 +77,25 @@ module Servactory
|
|
74
77
|
is_option_message_proc = option.message.is_a?(Proc) if is_option_message_present
|
75
78
|
|
76
79
|
lambda do |input: nil, internal: nil, output: nil, **attributes|
|
77
|
-
default_attributes = { **attributes, option_value: option.value }
|
80
|
+
default_attributes = { **attributes, option_name: option.name, option_value: option.value }
|
78
81
|
|
79
82
|
if Servactory::Utils.really_input?(input)
|
80
83
|
if is_option_message_present
|
81
|
-
is_option_message_proc ? option.message.call(**default_attributes.merge(input:
|
84
|
+
is_option_message_proc ? option.message.call(**default_attributes.merge(input:)) : option.message
|
82
85
|
else
|
83
|
-
message_for_input_with(**default_attributes.merge(input:
|
86
|
+
message_for_input_with(**default_attributes.merge(input:))
|
84
87
|
end
|
85
88
|
elsif Servactory::Utils.really_internal?(internal)
|
86
89
|
if is_option_message_present
|
87
|
-
is_option_message_proc ? option.message.call(**default_attributes.merge(internal:
|
90
|
+
is_option_message_proc ? option.message.call(**default_attributes.merge(internal:)) : option.message
|
88
91
|
else
|
89
|
-
message_for_internal_with(**default_attributes.merge(internal:
|
92
|
+
message_for_internal_with(**default_attributes.merge(internal:))
|
90
93
|
end
|
91
94
|
elsif Servactory::Utils.really_output?(output)
|
92
95
|
if is_option_message_present
|
93
|
-
is_option_message_proc ? option.message.call(**default_attributes.merge(output:
|
96
|
+
is_option_message_proc ? option.message.call(**default_attributes.merge(output:)) : option.message
|
94
97
|
else
|
95
|
-
message_for_output_with(**default_attributes.merge(output:
|
98
|
+
message_for_output_with(**default_attributes.merge(output:))
|
96
99
|
end
|
97
100
|
end
|
98
101
|
end
|