servactory 2.5.2 → 2.6.0.rc2

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 +2 -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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0eb12b9f0b029bee8f4e2081ecba8c663cf96144dd3de1fbb558015e738875bf
4
- data.tar.gz: 873cd09732c52d92000e98bfda0c8419c6c78edb3cb574d0701c05b47446250f
3
+ metadata.gz: 3f69f28208e5c09f4ddd0e112ca8155ef288af67b5bc2c7035f12082ab968acc
4
+ data.tar.gz: 97820e7d44399d15b077091e4c7eb3956444a7e456dd6a8e51fd49caa21b7431
5
5
  SHA512:
6
- metadata.gz: b5cd6c0bfe803edcf12c7b40e90f6660c2aba527ea24e29d87b905a497fe8d3d510ca06cd6c76087e37dc075a545e21516cbd625245133b0443cda2a3b0a8a94
7
- data.tar.gz: 581854dc492e0a6bacb139caa50ec8a11a69924d46c6f30fd345f3118df672b6593be06f02a6093b5a0d225062e1d5ec44a4419df70b0cc8537b82a034ba8df2
6
+ metadata.gz: 4bcf546de124b1d5cae91b2b9288a6a68ce0fcbab0a343166a112505df3671f6f5d33aa5dcd600b8f98f2ef51e7b457bf272ffc43fab6bd5b9c050f938db2e93
7
+ data.tar.gz: 89022378fefc711217f6ec2176613b4beaa3b16e6afe3ae01f0c73e3462f32f3c50dd746db2abd61eb2cc97ada91f7925001b5492ceacd9a73b0dcfdf7e6ae3a
@@ -18,6 +18,9 @@ en:
18
18
  default_error: "[%{service_class_name}] Input `%{input_name}` must \"%{code}\""
19
19
  syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{input_name}` input: %{exception_message}"
20
20
  dynamic_options:
21
+ consists_of:
22
+ required: "[%{service_class_name}] Required element in input collection `%{input_name}` is missing"
23
+ wrong_type: "[%{service_class_name}] Wrong element type in input collection `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
21
24
  format:
22
25
  default: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
23
26
  wrong_pattern: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
@@ -29,13 +32,9 @@ en:
29
32
  required:
30
33
  default_error:
31
34
  default: "[%{service_class_name}] Required input `%{input_name}` is missing"
32
- for_collection: "[%{service_class_name}] Required element in input collection `%{input_name}` is missing"
33
35
  type:
34
36
  default_error:
35
37
  default: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
36
- for_collection:
37
- wrong_type: "[%{service_class_name}] Wrong input collection type `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
38
- wrong_element_type: "[%{service_class_name}] Wrong type in input collection `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
39
38
  for_hash:
40
39
  wrong_element_type: "[%{service_class_name}] Wrong type in input hash `%{input_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
41
40
  tools:
@@ -54,6 +53,9 @@ en:
54
53
  default_error: "[%{service_class_name}] Internal attribute `%{internal_name}` must \"%{code}\""
55
54
  syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{internal_name}` internal attribute: %{exception_message}"
56
55
  dynamic_options:
56
+ consists_of:
57
+ required: "[%{service_class_name}] Required element in internal attribute collection `%{internal_name}` is missing"
58
+ wrong_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
57
59
  format:
58
60
  default: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
59
61
  wrong_pattern: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
@@ -65,9 +67,6 @@ en:
65
67
  type:
66
68
  default_error:
67
69
  default: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
68
- for_collection:
69
- wrong_type: "[%{service_class_name}] Wrong internal attribute collection type `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
70
- wrong_element_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
71
70
  for_hash:
72
71
  wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
73
72
  outputs:
@@ -81,6 +80,9 @@ en:
81
80
  default_error: "[%{service_class_name}] Output attribute `%{output_name}` must \"%{code}\""
82
81
  syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{output_name}` output attribute: %{exception_message}"
83
82
  dynamic_options:
83
+ consists_of:
84
+ required: "[%{service_class_name}] Required element in output attribute collection `%{output_name}` is missing"
85
+ wrong_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
84
86
  format:
85
87
  default: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
86
88
  wrong_pattern: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
@@ -92,8 +94,5 @@ en:
92
94
  type:
93
95
  default_error:
94
96
  default: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
95
- for_collection:
96
- wrong_type: "[%{service_class_name}] Wrong output attribute collection type `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
97
- wrong_element_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
98
97
  for_hash:
99
98
  wrong_element_type: "[%{service_class_name}] Wrong type in output attribute hash `%{output_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
@@ -18,6 +18,9 @@ ru:
18
18
  default_error: "[%{service_class_name}] Инпут `%{input_name}` должен \"%{code}\""
19
19
  syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` инпута `%{input_name}`: %{exception_message}"
20
20
  dynamic_options:
21
+ consists_of:
22
+ required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции инпута `%{input_name}`"
23
+ wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
21
24
  format:
22
25
  default: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
23
26
  wrong_pattern: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
@@ -29,16 +32,11 @@ ru:
29
32
  required:
30
33
  default_error:
31
34
  default: "[%{service_class_name}] Обязательный инпут `%{input_name}` отсутствует"
32
- for_collection: "[%{service_class_name}] Обязательный элемент в коллекции инпута `%{input_name}` отсутствует"
33
35
  type:
34
36
  default_error:
35
37
  default: "[%{service_class_name}] Неправильный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
36
- for_collection:
37
- wrong_type: "[%{service_class_name}] Неправильный тип коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
38
- wrong_element_type: "[%{service_class_name}] Неправильный тип в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
39
38
  for_hash:
40
39
  wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
41
-
42
40
  tools:
43
41
  find_unnecessary:
44
42
  error: "[%{service_class_name}] Неожиданные атрибуты: `%{unnecessary_attributes}`"
@@ -55,6 +53,9 @@ ru:
55
53
  default_error: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` должен \"%{code}\""
56
54
  syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` внутреннего атрибута `%{internal_name}`: %{exception_message}"
57
55
  dynamic_options:
56
+ consists_of:
57
+ required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции внутреннего атрибута `%{internal_name}`"
58
+ wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
58
59
  format:
59
60
  default: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
60
61
  wrong_pattern: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
@@ -66,9 +67,6 @@ ru:
66
67
  type:
67
68
  default_error:
68
69
  default: "[%{service_class_name}] Неправильный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
69
- for_collection:
70
- wrong_type: "[%{service_class_name}] Неправильный тип коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
71
- wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
72
70
  for_hash:
73
71
  wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
74
72
  outputs:
@@ -82,6 +80,9 @@ ru:
82
80
  default_error: "[%{service_class_name}] Выходящий атрибут `%{output_name}` должен \"%{code}\""
83
81
  syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` выходящего атрибута `%{output_name}`: %{exception_message}"
84
82
  dynamic_options:
83
+ consists_of:
84
+ required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции выходящего атрибута `%{output_name}`"
85
+ wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
85
86
  format:
86
87
  default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
87
88
  wrong_pattern: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
@@ -92,8 +93,5 @@ ru:
92
93
  default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` получил значение `%{value}`, которое больше `%{option_value}`"
93
94
  type:
94
95
  default: "[%{service_class_name}] Неправильный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
95
- for_collection:
96
- wrong_type: "[%{service_class_name}] Неправильный тип коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
97
- wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
98
96
  for_hash:
99
97
  wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
@@ -48,14 +48,14 @@ module ApplicationService
48
48
  # ]
49
49
  # )
50
50
 
51
- # collection_mode_class_names [ActiveRecord::Relation]
52
-
53
51
  # hash_mode_class_names [CustomHash]
54
52
 
55
53
  # action_shortcuts %i[assign build create save]
56
54
 
57
55
  # action_aliases %i[do_it!]
58
56
 
57
+ # i18n_root_key :servactory
58
+
59
59
  # predicate_methods_enabled false
60
60
  end
61
61
  end
@@ -58,9 +58,8 @@ module Servactory
58
58
  def raise_message_with!(formatted_text)
59
59
  raise @context.class.config.failure_class.new(
60
60
  type: :base,
61
- message: I18n.t(
62
- "servactory.methods.cannot_be_overwritten",
63
- service_class_name: @context.class.name,
61
+ message: @context.send(:servactory_service_info).translate(
62
+ "methods.cannot_be_overwritten",
64
63
  list_of_methods: formatted_text
65
64
  )
66
65
  )
@@ -20,8 +20,6 @@ module Servactory
20
20
 
21
21
  child.config.result_class = config.result_class
22
22
 
23
- child.config.collection_mode_class_names = config.collection_mode_class_names
24
-
25
23
  child.config.input_option_helpers = config.input_option_helpers
26
24
  child.config.internal_option_helpers = config.internal_option_helpers
27
25
  child.config.output_option_helpers = config.output_option_helpers
@@ -30,6 +28,8 @@ module Servactory
30
28
  child.config.action_shortcuts = config.action_shortcuts
31
29
  child.config.action_rescue_handlers = config.action_rescue_handlers
32
30
 
31
+ child.config.i18n_root_key = config.i18n_root_key
32
+
33
33
  child.config.predicate_methods_enabled = config.predicate_methods_enabled
34
34
  end
35
35
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Configuration
5
- class Factory
5
+ class Factory # rubocop:disable Metrics/ClassLength
6
6
  def initialize(config)
7
7
  @config = config
8
8
  end
@@ -69,10 +69,6 @@ module Servactory
69
69
  raise_error_about_wrong_result_class_with(:result_class, result_class)
70
70
  end
71
71
 
72
- def collection_mode_class_names(collection_mode_class_names)
73
- @config.collection_mode_class_names.merge(collection_mode_class_names)
74
- end
75
-
76
72
  def hash_mode_class_names(hash_mode_class_names)
77
73
  @config.hash_mode_class_names.merge(hash_mode_class_names)
78
74
  end
@@ -97,6 +93,12 @@ module Servactory
97
93
  @config.action_shortcuts.merge(action_shortcuts)
98
94
  end
99
95
 
96
+ def i18n_root_key(value)
97
+ return @config.i18n_root_key = value.to_s if i18n_key?(value)
98
+
99
+ raise_error_about_wrong_i18n_root_key_with(:i18n_root_key, value)
100
+ end
101
+
100
102
  def predicate_methods_enabled(flag)
101
103
  return @config.predicate_methods_enabled = flag if boolean?(flag)
102
104
 
@@ -117,6 +119,10 @@ module Servactory
117
119
  value.is_a?(Class) && value <= Servactory::Result
118
120
  end
119
121
 
122
+ def i18n_key?(value)
123
+ value.is_a?(Symbol) || (value.is_a?(String) && value.present?)
124
+ end
125
+
120
126
  def boolean?(value)
121
127
  value.is_a?(TrueClass) || value.is_a?(FalseClass)
122
128
  end
@@ -137,10 +143,17 @@ module Servactory
137
143
  "See configuration example here: https://servactory.com/guide/configuration"
138
144
  end
139
145
 
146
+ def raise_error_about_wrong_i18n_root_key_with(config_name, value)
147
+ raise ArgumentError,
148
+ "Error in `#{config_name}` configuration. " \
149
+ "The `#{value.inspect}` value must be `Symbol` or `String`. " \
150
+ "See configuration example here: https://servactory.com/guide/configuration"
151
+ end
152
+
140
153
  def raise_error_about_wrong_predicate_methods_enabled_with(config_name, value)
141
154
  raise ArgumentError,
142
155
  "Error in `#{config_name}` configuration. " \
143
- "The `#{value}` value must be `TrueClass` or `FalseClass`. " \
156
+ "The `#{value.inspect}` value must be `TrueClass` or `FalseClass`. " \
144
157
  "See configuration example here: https://servactory.com/guide/configuration"
145
158
  end
146
159
  end
@@ -9,7 +9,6 @@ module Servactory
9
9
  :success_class,
10
10
  :failure_class,
11
11
  :result_class,
12
- :collection_mode_class_names,
13
12
  :hash_mode_class_names,
14
13
  :input_option_helpers,
15
14
  :internal_option_helpers,
@@ -17,6 +16,7 @@ module Servactory
17
16
  :action_aliases,
18
17
  :action_shortcuts,
19
18
  :action_rescue_handlers,
19
+ :i18n_root_key,
20
20
  :predicate_methods_enabled
21
21
 
22
22
  def initialize # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@@ -29,9 +29,6 @@ module Servactory
29
29
 
30
30
  @result_class = Servactory::Result
31
31
 
32
- @collection_mode_class_names =
33
- Servactory::Maintenance::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
34
-
35
32
  @hash_mode_class_names =
36
33
  Servactory::Maintenance::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
37
34
 
@@ -39,15 +36,17 @@ module Servactory
39
36
  Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_input_option_helpers)
40
37
 
41
38
  @internal_option_helpers =
42
- Servactory::Maintenance::Attributes::OptionHelpersCollection.new
39
+ Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_internal_option_helpers)
43
40
 
44
41
  @output_option_helpers =
45
- Servactory::Maintenance::Attributes::OptionHelpersCollection.new
42
+ Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_output_option_helpers)
46
43
 
47
44
  @action_aliases = Servactory::Actions::Aliases::Collection.new
48
45
  @action_shortcuts = Servactory::Actions::Shortcuts::Collection.new
49
46
  @action_rescue_handlers = Servactory::Actions::RescueHandlers::Collection.new
50
47
 
48
+ @i18n_root_key = "servactory"
49
+
51
50
  @predicate_methods_enabled = true
52
51
  end
53
52
 
@@ -57,10 +56,6 @@ module Servactory
57
56
 
58
57
  private
59
58
 
60
- def default_collection_mode_class_names
61
- Set[Array, Set]
62
- end
63
-
64
59
  def default_hash_mode_class_names
65
60
  Set[Hash]
66
61
  end
@@ -68,6 +63,19 @@ module Servactory
68
63
  def default_input_option_helpers
69
64
  Set[
70
65
  Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
66
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
67
+ ]
68
+ end
69
+
70
+ def default_internal_option_helpers
71
+ Set[
72
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
73
+ ]
74
+ end
75
+
76
+ def default_output_option_helpers
77
+ Set[
78
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
71
79
  ]
72
80
  end
73
81
  end
@@ -99,9 +99,8 @@ module Servactory
99
99
  end
100
100
 
101
101
  def raise_error_for(type, name)
102
- message_text = I18n.t(
103
- "servactory.inputs.undefined.#{type}",
104
- service_class_name: @context.class.name,
102
+ message_text = @context.send(:servactory_service_info).translate(
103
+ "inputs.undefined.#{type}",
105
104
  input_name: name
106
105
  )
107
106
 
@@ -69,9 +69,8 @@ module Servactory
69
69
  end
70
70
 
71
71
  def raise_error_for(type, name)
72
- message_text = I18n.t(
73
- "servactory.internals.undefined.#{type}",
74
- service_class_name: @context.class.name,
72
+ message_text = @context.send(:servactory_service_info).translate(
73
+ "internals.undefined.#{type}",
75
74
  internal_name: name
76
75
  )
77
76
 
@@ -69,9 +69,8 @@ module Servactory
69
69
  end
70
70
 
71
71
  def raise_error_for(type, name)
72
- message_text = I18n.t(
73
- "servactory.outputs.undefined.#{type}",
74
- service_class_name: @context.class.name,
72
+ message_text = @context.send(:servactory_service_info).translate(
73
+ "outputs.undefined.#{type}",
75
74
  output_name: name
76
75
  )
77
76
 
@@ -3,6 +3,23 @@
3
3
  module Servactory
4
4
  module Context
5
5
  module Workspace
6
+ class Actor
7
+ attr_reader :class_name
8
+
9
+ def initialize(context)
10
+ @class_name = context.class.name
11
+ @i18n_root_key = context.class.config.i18n_root_key
12
+ end
13
+
14
+ def translate(key, **options)
15
+ I18n.t(
16
+ "#{@i18n_root_key}.#{key}",
17
+ service_class_name: class_name,
18
+ **options
19
+ )
20
+ end
21
+ end
22
+
6
23
  def inputs
7
24
  @inputs ||= Inputs.new(
8
25
  context: self,
@@ -100,13 +117,16 @@ module Servactory
100
117
  def call
101
118
  raise self.class.config.failure_class.new(
102
119
  type: :base,
103
- message: I18n.t(
104
- "servactory.methods.call.not_used",
105
- service_class_name: self.class.name
120
+ message: servactory_service_info.translate(
121
+ "methods.call.not_used"
106
122
  )
107
123
  )
108
124
  end
109
125
 
126
+ def servactory_service_info
127
+ @servactory_service_info ||= self.class::Actor.new(self)
128
+ end
129
+
110
130
  def servactory_service_store
111
131
  @servactory_service_store ||= Store.new(self)
112
132
  end
@@ -11,8 +11,7 @@ module Servactory
11
11
  def info # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
12
  Servactory::Info::Result.new(
13
13
  inputs: collection_of_inputs.to_h do |input|
14
- work = input.class::Work.new(input)
15
- consists_of = input.collection_of_options.find_by(name: :consists_of)
14
+ work = input.class::Actor.new(input)
16
15
  inclusion = input.collection_of_options.find_by(name: :inclusion)
17
16
  must = input.collection_of_options.find_by(name: :must)
18
17
 
@@ -23,7 +22,6 @@ module Servactory
23
22
  types: input.types,
24
23
  required: input.required,
25
24
  default: input.default,
26
- consists_of: consists_of.body,
27
25
  inclusion: inclusion.body,
28
26
  must: must.body
29
27
  }
@@ -31,8 +29,7 @@ module Servactory
31
29
  end,
32
30
 
33
31
  internals: collection_of_internals.to_h do |internal|
34
- work = internal.class::Work.new(internal)
35
- consists_of = internal.collection_of_options.find_by(name: :consists_of)
32
+ work = internal.class::Actor.new(internal)
36
33
  inclusion = internal.collection_of_options.find_by(name: :inclusion)
37
34
  must = internal.collection_of_options.find_by(name: :must)
38
35
 
@@ -41,7 +38,6 @@ module Servactory
41
38
  {
42
39
  work: work,
43
40
  types: internal.types,
44
- consists_of: consists_of.body,
45
41
  inclusion: inclusion.body,
46
42
  must: must.body
47
43
  }
@@ -49,8 +45,7 @@ module Servactory
49
45
  end,
50
46
 
51
47
  outputs: collection_of_outputs.to_h do |output|
52
- work = output.class::Work.new(output)
53
- consists_of = output.collection_of_options.find_by(name: :consists_of)
48
+ work = output.class::Actor.new(output)
54
49
  inclusion = output.collection_of_options.find_by(name: :inclusion)
55
50
  must = output.collection_of_options.find_by(name: :must)
56
51
 
@@ -59,7 +54,6 @@ module Servactory
59
54
  {
60
55
  work: work,
61
56
  types: output.types,
62
- consists_of: consists_of.body,
63
57
  inclusion: inclusion.body,
64
58
  must: must.body
65
59
  }
@@ -21,7 +21,6 @@ module Servactory
21
21
  collection_of_inputs << Input.new(
22
22
  name,
23
23
  *helpers,
24
- collection_mode_class_names: config.collection_mode_class_names,
25
24
  hash_mode_class_names: config.hash_mode_class_names,
26
25
  option_helpers: config.input_option_helpers,
27
26
  **options
@@ -3,7 +3,7 @@
3
3
  module Servactory
4
4
  module Inputs
5
5
  class Input
6
- class Work
6
+ class Actor
7
7
  attr_reader :name,
8
8
  :internal_name,
9
9
  :types,
@@ -35,14 +35,12 @@ module Servactory
35
35
  name,
36
36
  *helpers,
37
37
  as: nil,
38
- collection_mode_class_names:,
39
38
  hash_mode_class_names:,
40
39
  option_helpers:,
41
40
  **options
42
41
  )
43
42
  @name = name
44
43
  @internal_name = as.present? ? as : name
45
- @collection_mode_class_names = collection_mode_class_names
46
44
  @hash_mode_class_names = hash_mode_class_names
47
45
  @option_helpers = option_helpers
48
46
 
@@ -70,14 +68,12 @@ module Servactory
70
68
 
71
69
  options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
72
70
  attribute: self,
73
- collection_mode_class_names: @collection_mode_class_names,
74
71
  hash_mode_class_names: @hash_mode_class_names,
75
72
  options: options,
76
73
  features: {
77
74
  required: true,
78
75
  types: true,
79
76
  default: true,
80
- collection: true,
81
77
  hash: true,
82
78
  inclusion: true,
83
79
  must: true,
@@ -106,7 +102,7 @@ module Servactory
106
102
  prepared_options.deep_merge!(prepared_option)
107
103
  end
108
104
 
109
- options.merge(prepared_options)
105
+ options.deep_merge(prepared_options)
110
106
  end
111
107
 
112
108
  def options_for_checks
@@ -28,9 +28,8 @@ module Servactory
28
28
  end
29
29
 
30
30
  def raise_error_for(input)
31
- message_text = I18n.t(
32
- "servactory.inputs.tools.rules.error",
33
- service_class_name: @context.class.name,
31
+ message_text = @context.send(:servactory_service_info).translate(
32
+ "inputs.tools.rules.error",
34
33
  input_name: input.name,
35
34
  conflict_code: input.conflict_code
36
35
  )
@@ -17,9 +17,8 @@ module Servactory
17
17
  def find!
18
18
  return if unnecessary_attributes.empty?
19
19
 
20
- message_text = I18n.t(
21
- "servactory.inputs.tools.find_unnecessary.error",
22
- service_class_name: @context.class.name,
20
+ message_text = @context.send(:servactory_service_info).translate(
21
+ "inputs.tools.find_unnecessary.error",
23
22
  unnecessary_attributes: unnecessary_attributes.join(", ")
24
23
  )
25
24
 
@@ -7,13 +7,9 @@ module Servactory
7
7
  module_function
8
8
 
9
9
  def default_message
10
- lambda do |service_class_name:, input:, value:|
11
- i18n_key = "servactory.inputs.validations.required.default_error."
12
- i18n_key += input.collection_mode? && value.present? ? "for_collection" : "default"
13
-
14
- I18n.t(
15
- i18n_key,
16
- service_class_name: service_class_name,
10
+ lambda do |service:, input:, **|
11
+ service.translate(
12
+ "inputs.validations.required.default_error.default",
17
13
  input_name: input.name
18
14
  )
19
15
  end
@@ -25,11 +25,7 @@ module Servactory
25
25
  end
26
26
 
27
27
  def check
28
- if @input.collection_mode? && Servactory::Utils.value_present?(@value)
29
- return if collection_valid?
30
- elsif Servactory::Utils.value_present?(@value)
31
- return
32
- end
28
+ return if Servactory::Utils.value_present?(@value)
33
29
 
34
30
  _, message = @input.required.values_at(:is, :message)
35
31
 
@@ -38,18 +34,10 @@ module Servactory
38
34
 
39
35
  private
40
36
 
41
- def collection_valid?
42
- collection_valid_for?(values: @value)
43
- end
44
-
45
- def collection_valid_for?(values:)
46
- values.respond_to?(:all?) && values.flatten.all?(&:present?)
47
- end
48
-
49
37
  def add_error_with(message)
50
38
  add_error(
51
39
  message: message.presence || Servactory::Inputs::Translator::Required.default_message,
52
- service_class_name: @context.class.name,
40
+ service: @context.send(:servactory_service_info),
53
41
  input: @input,
54
42
  value: @value
55
43
  )
@@ -20,7 +20,6 @@ module Servactory
20
20
  collection_of_internals << Internal.new(
21
21
  name,
22
22
  *helpers,
23
- collection_mode_class_names: config.collection_mode_class_names,
24
23
  hash_mode_class_names: config.hash_mode_class_names,
25
24
  option_helpers: config.internal_option_helpers,
26
25
  **options
@@ -3,7 +3,7 @@
3
3
  module Servactory
4
4
  module Internals
5
5
  class Internal
6
- class Work
6
+ class Actor
7
7
  attr_reader :name,
8
8
  :types,
9
9
  :inclusion
@@ -28,13 +28,11 @@ module Servactory
28
28
  def initialize(
29
29
  name,
30
30
  *helpers,
31
- collection_mode_class_names:,
32
31
  hash_mode_class_names:,
33
32
  option_helpers:,
34
33
  **options
35
34
  )
36
35
  @name = name
37
- @collection_mode_class_names = collection_mode_class_names
38
36
  @hash_mode_class_names = hash_mode_class_names
39
37
  @option_helpers = option_helpers
40
38
 
@@ -61,12 +59,10 @@ module Servactory
61
59
 
62
60
  options_registrar = Servactory::Maintenance::Attributes::Options::Registrar.register(
63
61
  attribute: self,
64
- collection_mode_class_names: @collection_mode_class_names,
65
62
  hash_mode_class_names: @hash_mode_class_names,
66
63
  options: options,
67
64
  features: {
68
65
  types: true,
69
- collection: true,
70
66
  hash: true,
71
67
  inclusion: true,
72
68
  must: true
@@ -94,7 +90,7 @@ module Servactory
94
90
  prepared_options.deep_merge!(prepared_option)
95
91
  end
96
92
 
97
- options.merge(prepared_options)
93
+ options.deep_merge(prepared_options)
98
94
  end
99
95
 
100
96
  def options_for_checks