servactory 2.5.2 → 2.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/locales/en.yml +9 -10
- data/config/locales/ru.yml +9 -11
- data/lib/generators/servactory/templates/services/application_service/base.rb +2 -2
- data/lib/servactory/actions/tools/rules.rb +2 -3
- data/lib/servactory/configuration/dsl.rb +0 -2
- data/lib/servactory/configuration/factory.rb +19 -6
- data/lib/servactory/configuration/setup.rb +18 -10
- data/lib/servactory/context/workspace/inputs.rb +2 -3
- data/lib/servactory/context/workspace/internals.rb +2 -3
- data/lib/servactory/context/workspace/outputs.rb +2 -3
- data/lib/servactory/context/workspace.rb +23 -3
- data/lib/servactory/info/dsl.rb +3 -9
- data/lib/servactory/inputs/dsl.rb +0 -1
- data/lib/servactory/inputs/input.rb +2 -6
- data/lib/servactory/inputs/tools/rules.rb +2 -3
- data/lib/servactory/inputs/tools/unnecessary.rb +2 -3
- data/lib/servactory/inputs/translator/required.rb +3 -7
- data/lib/servactory/inputs/validations/required.rb +2 -14
- data/lib/servactory/internals/dsl.rb +0 -1
- data/lib/servactory/internals/internal.rb +2 -6
- data/lib/servactory/maintenance/attributes/options/registrar.rb +2 -34
- data/lib/servactory/maintenance/attributes/translator/inclusion.rb +3 -4
- data/lib/servactory/maintenance/attributes/translator/must.rb +8 -10
- data/lib/servactory/maintenance/attributes/translator/type.rb +11 -46
- data/lib/servactory/maintenance/attributes/validations/inclusion.rb +1 -1
- data/lib/servactory/maintenance/attributes/validations/must.rb +2 -2
- data/lib/servactory/maintenance/validations/types.rb +4 -30
- data/lib/servactory/outputs/dsl.rb +0 -1
- data/lib/servactory/outputs/output.rb +2 -6
- data/lib/servactory/result.rb +2 -3
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +8 -56
- data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/must_matcher.rb +7 -2
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/required_matcher.rb +5 -2
- data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +18 -62
- data/lib/servactory/tool_kit/dynamic_options/consists_of.rb +92 -0
- data/lib/servactory/tool_kit/dynamic_options/format.rb +9 -12
- data/lib/servactory/tool_kit/dynamic_options/max.rb +9 -12
- data/lib/servactory/tool_kit/dynamic_options/min.rb +9 -12
- data/lib/servactory/utils.rb +3 -3
- data/lib/servactory/version.rb +3 -3
- metadata +3 -4
- data/lib/servactory/maintenance/collection_mode/class_names_collection.rb +0 -16
- data/lib/servactory/maintenance/validations/collection.rb +0 -86
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module ToolKit
|
5
|
+
module DynamicOptions
|
6
|
+
class ConsistsOf < Must
|
7
|
+
COLLECTION_CLASS_NAMES = [Array, Set].freeze
|
8
|
+
private_constant :COLLECTION_CLASS_NAMES
|
9
|
+
|
10
|
+
def self.setup(option_name = :consists_of)
|
11
|
+
new(option_name, :type, false).must(:consists_of)
|
12
|
+
end
|
13
|
+
|
14
|
+
def condition_for_input_with(input:, value:, option:)
|
15
|
+
common_condition_with(attribute: input, value: value, option: option)
|
16
|
+
end
|
17
|
+
|
18
|
+
def condition_for_internal_with(internal:, value:, option:)
|
19
|
+
common_condition_with(attribute: internal, value: value, option: option)
|
20
|
+
end
|
21
|
+
|
22
|
+
def condition_for_output_with(output:, value:, option:)
|
23
|
+
common_condition_with(attribute: output, value: value, option: option)
|
24
|
+
end
|
25
|
+
|
26
|
+
def common_condition_with(attribute:, value:, option:)
|
27
|
+
return true if option.value == false
|
28
|
+
return false if COLLECTION_CLASS_NAMES.intersection(attribute.types).empty?
|
29
|
+
|
30
|
+
validate_for!(values: value, option: option)
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_for!(values:, option:)
|
34
|
+
consists_of_types = Array(option.value)
|
35
|
+
|
36
|
+
return [false, :required] if !consists_of_types.include?(NilClass) && !values.flatten.all?(&:present?)
|
37
|
+
|
38
|
+
return true if values.flatten.all? do |value|
|
39
|
+
consists_of_types.include?(value.class)
|
40
|
+
end
|
41
|
+
|
42
|
+
[false, :wrong_type]
|
43
|
+
end
|
44
|
+
|
45
|
+
########################################################################
|
46
|
+
|
47
|
+
def message_for_input_with(service:, input:, value:, option_value:, reason:, **)
|
48
|
+
i18n_key = "servactory.inputs.validations.must.dynamic_options.consists_of"
|
49
|
+
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
50
|
+
|
51
|
+
I18n.t(
|
52
|
+
i18n_key,
|
53
|
+
service_class_name: service.class_name,
|
54
|
+
input_name: input.name,
|
55
|
+
expected_type: Array(option_value).uniq.join(", "),
|
56
|
+
given_type: given_type_for(values: value, option_value: option_value)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def message_for_internal_with(service:, internal:, value:, option_value:, reason:, **)
|
61
|
+
i18n_key = "servactory.internals.validations.must.dynamic_options.consists_of"
|
62
|
+
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
63
|
+
|
64
|
+
I18n.t(
|
65
|
+
i18n_key,
|
66
|
+
service_class_name: service.class_name,
|
67
|
+
internal_name: internal.name,
|
68
|
+
expected_type: Array(option_value).uniq.join(", "),
|
69
|
+
given_type: given_type_for(values: value, option_value: option_value)
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def message_for_output_with(service:, output:, value:, option_value:, reason:, **)
|
74
|
+
i18n_key = "servactory.outputs.validations.must.dynamic_options.consists_of"
|
75
|
+
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
76
|
+
|
77
|
+
I18n.t(
|
78
|
+
i18n_key,
|
79
|
+
service_class_name: service.class_name,
|
80
|
+
output_name: output.name,
|
81
|
+
expected_type: Array(option_value).uniq.join(", "),
|
82
|
+
given_type: given_type_for(values: value, option_value: option_value)
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def given_type_for(values:, option_value:)
|
87
|
+
values.flatten.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -98,39 +98,36 @@ module Servactory
|
|
98
98
|
|
99
99
|
########################################################################
|
100
100
|
|
101
|
-
def message_for_input_with(
|
102
|
-
i18n_key = "
|
101
|
+
def message_for_input_with(service:, input:, value:, option_value:, reason:, **)
|
102
|
+
i18n_key = "inputs.validations.must.dynamic_options.format"
|
103
103
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
104
104
|
|
105
|
-
|
105
|
+
service.translate(
|
106
106
|
i18n_key,
|
107
|
-
service_class_name: service_class_name,
|
108
107
|
input_name: input.name,
|
109
108
|
value: value,
|
110
109
|
format_name: option_value.present? ? option_value : option_value.inspect
|
111
110
|
)
|
112
111
|
end
|
113
112
|
|
114
|
-
def message_for_internal_with(
|
115
|
-
i18n_key = "
|
113
|
+
def message_for_internal_with(service:, internal:, value:, option_value:, reason:, **)
|
114
|
+
i18n_key = "internals.validations.must.dynamic_options.format"
|
116
115
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
117
116
|
|
118
|
-
|
117
|
+
service.translate(
|
119
118
|
i18n_key,
|
120
|
-
service_class_name: service_class_name,
|
121
119
|
internal_name: internal.name,
|
122
120
|
value: value,
|
123
121
|
format_name: option_value.present? ? option_value : option_value.inspect
|
124
122
|
)
|
125
123
|
end
|
126
124
|
|
127
|
-
def message_for_output_with(
|
128
|
-
i18n_key = "
|
125
|
+
def message_for_output_with(service:, output:, value:, option_value:, reason:, **)
|
126
|
+
i18n_key = "outputs.validations.must.dynamic_options.format"
|
129
127
|
i18n_key += reason.present? ? ".#{reason}" : ".default"
|
130
128
|
|
131
|
-
|
129
|
+
service.translate(
|
132
130
|
i18n_key,
|
133
|
-
service_class_name: service_class_name,
|
134
131
|
output_name: output.name,
|
135
132
|
value: value,
|
136
133
|
format_name: option_value.present? ? option_value : option_value.inspect
|
@@ -33,30 +33,27 @@ module Servactory
|
|
33
33
|
|
34
34
|
########################################################################
|
35
35
|
|
36
|
-
def message_for_input_with(
|
37
|
-
|
38
|
-
"
|
39
|
-
service_class_name: service_class_name,
|
36
|
+
def message_for_input_with(service:, input:, value:, option_value:, **)
|
37
|
+
service.translate(
|
38
|
+
"inputs.validations.must.dynamic_options.max.default",
|
40
39
|
input_name: input.name,
|
41
40
|
value: value,
|
42
41
|
option_value: option_value
|
43
42
|
)
|
44
43
|
end
|
45
44
|
|
46
|
-
def message_for_internal_with(
|
47
|
-
|
48
|
-
"
|
49
|
-
service_class_name: service_class_name,
|
45
|
+
def message_for_internal_with(service:, internal:, value:, option_value:, **)
|
46
|
+
service.translate(
|
47
|
+
"internals.validations.must.dynamic_options.max.default",
|
50
48
|
internal_name: internal.name,
|
51
49
|
value: value,
|
52
50
|
option_value: option_value
|
53
51
|
)
|
54
52
|
end
|
55
53
|
|
56
|
-
def message_for_output_with(
|
57
|
-
|
58
|
-
"
|
59
|
-
service_class_name: service_class_name,
|
54
|
+
def message_for_output_with(service:, output:, value:, option_value:, **)
|
55
|
+
service.translate(
|
56
|
+
"outputs.validations.must.dynamic_options.max.default",
|
60
57
|
output_name: output.name,
|
61
58
|
value: value,
|
62
59
|
option_value: option_value
|
@@ -33,30 +33,27 @@ module Servactory
|
|
33
33
|
|
34
34
|
########################################################################
|
35
35
|
|
36
|
-
def message_for_input_with(
|
37
|
-
|
38
|
-
"
|
39
|
-
service_class_name: service_class_name,
|
36
|
+
def message_for_input_with(service:, input:, value:, option_value:, **)
|
37
|
+
service.translate(
|
38
|
+
"inputs.validations.must.dynamic_options.min.default",
|
40
39
|
input_name: input.name,
|
41
40
|
value: value,
|
42
41
|
option_value: option_value
|
43
42
|
)
|
44
43
|
end
|
45
44
|
|
46
|
-
def message_for_internal_with(
|
47
|
-
|
48
|
-
"
|
49
|
-
service_class_name: service_class_name,
|
45
|
+
def message_for_internal_with(service:, internal:, value:, option_value:, **)
|
46
|
+
service.translate(
|
47
|
+
"internals.validations.must.dynamic_options.min.default",
|
50
48
|
internal_name: internal.name,
|
51
49
|
value: value,
|
52
50
|
option_value: option_value
|
53
51
|
)
|
54
52
|
end
|
55
53
|
|
56
|
-
def message_for_output_with(
|
57
|
-
|
58
|
-
"
|
59
|
-
service_class_name: service_class_name,
|
54
|
+
def message_for_output_with(service:, output:, value:, option_value:, **)
|
55
|
+
service.translate(
|
56
|
+
"outputs.validations.must.dynamic_options.min.default",
|
60
57
|
output_name: output.name,
|
61
58
|
value: value,
|
62
59
|
option_value: option_value
|
data/lib/servactory/utils.rb
CHANGED
@@ -5,9 +5,9 @@ module Servactory
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
def fetch_hash_with_desired_attribute(attribute)
|
8
|
-
return { input: attribute.class::
|
9
|
-
return { internal: attribute.class::
|
10
|
-
return { output: attribute.class::
|
8
|
+
return { input: attribute.class::Actor.new(attribute) } if really_input?(attribute)
|
9
|
+
return { internal: attribute.class::Actor.new(attribute) } if really_internal?(attribute)
|
10
|
+
return { output: attribute.class::Actor.new(attribute) } if really_output?(attribute)
|
11
11
|
|
12
12
|
raise ArgumentError, "Failed to define attribute"
|
13
13
|
end
|
data/lib/servactory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -311,9 +311,7 @@ files:
|
|
311
311
|
- lib/servactory/maintenance/attributes/validations/inclusion.rb
|
312
312
|
- lib/servactory/maintenance/attributes/validations/must.rb
|
313
313
|
- lib/servactory/maintenance/attributes/validations/type.rb
|
314
|
-
- lib/servactory/maintenance/collection_mode/class_names_collection.rb
|
315
314
|
- lib/servactory/maintenance/hash_mode/class_names_collection.rb
|
316
|
-
- lib/servactory/maintenance/validations/collection.rb
|
317
315
|
- lib/servactory/maintenance/validations/object_schema.rb
|
318
316
|
- lib/servactory/maintenance/validations/types.rb
|
319
317
|
- lib/servactory/outputs/collection.rb
|
@@ -335,6 +333,7 @@ files:
|
|
335
333
|
- lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb
|
336
334
|
- lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb
|
337
335
|
- lib/servactory/test_kit/utils/faker.rb
|
336
|
+
- lib/servactory/tool_kit/dynamic_options/consists_of.rb
|
338
337
|
- lib/servactory/tool_kit/dynamic_options/format.rb
|
339
338
|
- lib/servactory/tool_kit/dynamic_options/max.rb
|
340
339
|
- lib/servactory/tool_kit/dynamic_options/min.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Servactory
|
4
|
-
module Maintenance
|
5
|
-
module CollectionMode
|
6
|
-
class ClassNamesCollection
|
7
|
-
extend Forwardable
|
8
|
-
def_delegators :@collection, :merge, :include?
|
9
|
-
|
10
|
-
def initialize(collection)
|
11
|
-
@collection = collection
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Servactory
|
4
|
-
module Maintenance
|
5
|
-
module Validations
|
6
|
-
class Collection
|
7
|
-
attr_reader :errors
|
8
|
-
|
9
|
-
def self.validate(...)
|
10
|
-
new(...).validate
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(types:, value:, consists_of:)
|
14
|
-
@types = types
|
15
|
-
@value = value
|
16
|
-
@consists_of = consists_of
|
17
|
-
|
18
|
-
@errors = []
|
19
|
-
end
|
20
|
-
|
21
|
-
def validate
|
22
|
-
unless @value.is_a?(prepared_type)
|
23
|
-
add_error(
|
24
|
-
expected_type: prepared_type.name,
|
25
|
-
given_type: @value.class.name
|
26
|
-
)
|
27
|
-
|
28
|
-
return self
|
29
|
-
end
|
30
|
-
|
31
|
-
validate_for!(values: @value)
|
32
|
-
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def valid?
|
37
|
-
@errors.empty?
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def validate_for!(values:) # rubocop:disable Metrics/MethodLength
|
43
|
-
values.each do |value|
|
44
|
-
value_type = value.class
|
45
|
-
|
46
|
-
if value_type == Array
|
47
|
-
validate_for!(values: value)
|
48
|
-
else
|
49
|
-
next if attribute_consists_of_types.include?(value_type)
|
50
|
-
|
51
|
-
add_error(
|
52
|
-
expected_type: attribute_consists_of_types.join(", "),
|
53
|
-
given_type: value_type.name
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
########################################################################
|
60
|
-
|
61
|
-
def prepared_type
|
62
|
-
@prepared_type ||= @types.fetch(0, Array)
|
63
|
-
end
|
64
|
-
|
65
|
-
def attribute_consists_of_types
|
66
|
-
@attribute_consists_of_types ||= prepared_types_from(Array(@consists_of.fetch(:type, [])))
|
67
|
-
end
|
68
|
-
|
69
|
-
def prepared_types_from(types)
|
70
|
-
types.map do |type|
|
71
|
-
Servactory::Utils.constantize_class(type)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
########################################################################
|
76
|
-
|
77
|
-
def add_error(expected_type:, given_type:)
|
78
|
-
@errors << {
|
79
|
-
expected_type: expected_type,
|
80
|
-
given_type: given_type
|
81
|
-
}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|