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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/en.yml +9 -10
  3. data/config/locales/ru.yml +9 -11
  4. data/lib/generators/servactory/templates/services/application_service/base.rb +2 -2
  5. data/lib/servactory/actions/tools/rules.rb +2 -3
  6. data/lib/servactory/configuration/dsl.rb +0 -2
  7. data/lib/servactory/configuration/factory.rb +19 -6
  8. data/lib/servactory/configuration/setup.rb +18 -10
  9. data/lib/servactory/context/workspace/inputs.rb +2 -3
  10. data/lib/servactory/context/workspace/internals.rb +2 -3
  11. data/lib/servactory/context/workspace/outputs.rb +2 -3
  12. data/lib/servactory/context/workspace.rb +23 -3
  13. data/lib/servactory/info/dsl.rb +3 -9
  14. data/lib/servactory/inputs/dsl.rb +0 -1
  15. data/lib/servactory/inputs/input.rb +2 -6
  16. data/lib/servactory/inputs/tools/rules.rb +2 -3
  17. data/lib/servactory/inputs/tools/unnecessary.rb +2 -3
  18. data/lib/servactory/inputs/translator/required.rb +3 -7
  19. data/lib/servactory/inputs/validations/required.rb +2 -14
  20. data/lib/servactory/internals/dsl.rb +0 -1
  21. data/lib/servactory/internals/internal.rb +2 -6
  22. data/lib/servactory/maintenance/attributes/options/registrar.rb +2 -34
  23. data/lib/servactory/maintenance/attributes/translator/inclusion.rb +3 -4
  24. data/lib/servactory/maintenance/attributes/translator/must.rb +8 -10
  25. data/lib/servactory/maintenance/attributes/translator/type.rb +11 -46
  26. data/lib/servactory/maintenance/attributes/validations/inclusion.rb +1 -1
  27. data/lib/servactory/maintenance/attributes/validations/must.rb +2 -2
  28. data/lib/servactory/maintenance/validations/types.rb +4 -30
  29. data/lib/servactory/outputs/dsl.rb +0 -1
  30. data/lib/servactory/outputs/output.rb +2 -6
  31. data/lib/servactory/result.rb +2 -3
  32. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +8 -56
  33. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/must_matcher.rb +7 -2
  34. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/required_matcher.rb +5 -2
  35. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +18 -62
  36. data/lib/servactory/tool_kit/dynamic_options/consists_of.rb +92 -0
  37. data/lib/servactory/tool_kit/dynamic_options/format.rb +9 -12
  38. data/lib/servactory/tool_kit/dynamic_options/max.rb +9 -12
  39. data/lib/servactory/tool_kit/dynamic_options/min.rb +9 -12
  40. data/lib/servactory/utils.rb +3 -3
  41. data/lib/servactory/version.rb +3 -3
  42. metadata +3 -4
  43. data/lib/servactory/maintenance/collection_mode/class_names_collection.rb +0 -16
  44. 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(service_class_name:, input:, value:, option_value:, reason:, **)
102
- i18n_key = "servactory.inputs.validations.must.dynamic_options.format"
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
- I18n.t(
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(service_class_name:, internal:, value:, option_value:, reason:, **)
115
- i18n_key = "servactory.internals.validations.must.dynamic_options.format"
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
- I18n.t(
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(service_class_name:, output:, value:, option_value:, reason:, **)
128
- i18n_key = "servactory.outputs.validations.must.dynamic_options.format"
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
- I18n.t(
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(service_class_name:, input:, value:, option_value:, **)
37
- I18n.t(
38
- "servactory.inputs.validations.must.dynamic_options.max.default",
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(service_class_name:, internal:, value:, option_value:, **)
47
- I18n.t(
48
- "servactory.internals.validations.must.dynamic_options.max.default",
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(service_class_name:, output:, value:, option_value:, **)
57
- I18n.t(
58
- "servactory.outputs.validations.must.dynamic_options.max.default",
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(service_class_name:, input:, value:, option_value:, **)
37
- I18n.t(
38
- "servactory.inputs.validations.must.dynamic_options.min.default",
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(service_class_name:, internal:, value:, option_value:, **)
47
- I18n.t(
48
- "servactory.internals.validations.must.dynamic_options.min.default",
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(service_class_name:, output:, value:, option_value:, **)
57
- I18n.t(
58
- "servactory.outputs.validations.must.dynamic_options.min.default",
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
@@ -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::Work.new(attribute) } if really_input?(attribute)
9
- return { internal: attribute.class::Work.new(attribute) } if really_internal?(attribute)
10
- return { output: attribute.class::Work.new(attribute) } if really_output?(attribute)
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
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 5
7
- PATCH = 2
8
- PRE = nil
6
+ MINOR = 6
7
+ PATCH = 0
8
+ PRE = "rc1"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
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.5.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-02 00:00:00.000000000 Z
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