servactory 2.16.1 → 3.0.0.rc1

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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -9
  3. data/config/locales/de.yml +134 -0
  4. data/config/locales/en.yml +15 -0
  5. data/config/locales/es.yml +134 -0
  6. data/config/locales/fr.yml +134 -0
  7. data/config/locales/it.yml +134 -0
  8. data/config/locales/ru.yml +15 -0
  9. data/lib/generators/README.md +45 -0
  10. data/lib/generators/servactory/base.rb +82 -0
  11. data/lib/generators/servactory/extension/USAGE +54 -0
  12. data/lib/generators/servactory/extension/extension_generator.rb +41 -0
  13. data/lib/generators/servactory/extension/templates/extension.rb.tt +62 -0
  14. data/lib/generators/servactory/install/USAGE +27 -0
  15. data/lib/generators/servactory/install/install_generator.rb +94 -0
  16. data/lib/generators/servactory/{templates/services/application_service/base.rb → install/templates/application_service/base.rb.tt} +29 -19
  17. data/lib/generators/servactory/{templates/services/application_service/exceptions.rb → install/templates/application_service/exceptions.rb.tt} +1 -1
  18. data/lib/generators/servactory/{templates/services/application_service/result.rb → install/templates/application_service/result.rb.tt} +1 -1
  19. data/lib/generators/servactory/rspec/USAGE +46 -0
  20. data/lib/generators/servactory/rspec/rspec_generator.rb +95 -0
  21. data/lib/generators/servactory/rspec/templates/service_spec.rb.tt +58 -0
  22. data/lib/generators/servactory/service/USAGE +51 -0
  23. data/lib/generators/servactory/service/service_generator.rb +56 -0
  24. data/lib/generators/servactory/service/templates/service.rb.tt +22 -0
  25. data/lib/servactory/actions/collection.rb +56 -1
  26. data/lib/servactory/actions/dsl.rb +11 -11
  27. data/lib/servactory/actions/tools/rules.rb +1 -1
  28. data/lib/servactory/actions/tools/runner.rb +111 -28
  29. data/lib/servactory/base.rb +1 -7
  30. data/lib/servactory/configuration/actions/aliases/collection.rb +5 -0
  31. data/lib/servactory/configuration/actions/rescue_handlers/collection.rb +5 -0
  32. data/lib/servactory/configuration/actions/shortcuts/collection.rb +5 -0
  33. data/lib/servactory/configuration/collection_mode/class_names_collection.rb +5 -0
  34. data/lib/servactory/configuration/config.rb +36 -0
  35. data/lib/servactory/configuration/configurable.rb +95 -0
  36. data/lib/servactory/configuration/dsl.rb +3 -27
  37. data/lib/servactory/configuration/factory.rb +20 -20
  38. data/lib/servactory/configuration/hash_mode/class_names_collection.rb +5 -0
  39. data/lib/servactory/configuration/option_helpers/option_helpers_collection.rb +5 -0
  40. data/lib/servactory/context/warehouse/inputs.rb +2 -2
  41. data/lib/servactory/context/workspace/inputs.rb +2 -2
  42. data/lib/servactory/context/workspace/internals.rb +2 -2
  43. data/lib/servactory/context/workspace/outputs.rb +2 -2
  44. data/lib/servactory/context/workspace.rb +11 -7
  45. data/lib/servactory/dsl.rb +10 -8
  46. data/lib/servactory/maintenance/attributes/tools/validation.rb +1 -1
  47. data/lib/servactory/result.rb +2 -2
  48. data/lib/servactory/stroma/dsl.rb +118 -0
  49. data/lib/servactory/stroma/entry.rb +32 -0
  50. data/lib/servactory/stroma/exceptions/base.rb +45 -0
  51. data/lib/servactory/stroma/exceptions/invalid_hook_type.rb +29 -0
  52. data/lib/servactory/stroma/exceptions/key_already_registered.rb +32 -0
  53. data/lib/servactory/stroma/exceptions/registry_frozen.rb +33 -0
  54. data/lib/servactory/stroma/exceptions/registry_not_finalized.rb +33 -0
  55. data/lib/servactory/stroma/exceptions/unknown_hook_target.rb +39 -0
  56. data/lib/servactory/stroma/hooks/applier.rb +63 -0
  57. data/lib/servactory/stroma/hooks/collection.rb +103 -0
  58. data/lib/servactory/stroma/hooks/factory.rb +80 -0
  59. data/lib/servactory/stroma/hooks/hook.rb +74 -0
  60. data/lib/servactory/stroma/registry.rb +94 -0
  61. data/lib/servactory/stroma/settings/collection.rb +90 -0
  62. data/lib/servactory/stroma/settings/registry_settings.rb +88 -0
  63. data/lib/servactory/stroma/settings/setting.rb +113 -0
  64. data/lib/servactory/stroma/state.rb +59 -0
  65. data/lib/servactory/test_kit/fake_type.rb +23 -0
  66. data/lib/servactory/test_kit/result.rb +45 -0
  67. data/lib/servactory/test_kit/rspec/helpers/argument_matchers.rb +97 -0
  68. data/lib/servactory/test_kit/rspec/helpers/concerns/error_messages.rb +179 -0
  69. data/lib/servactory/test_kit/rspec/helpers/concerns/service_class_validation.rb +74 -0
  70. data/lib/servactory/test_kit/rspec/helpers/fluent.rb +110 -0
  71. data/lib/servactory/test_kit/rspec/helpers/input_validator.rb +149 -0
  72. data/lib/servactory/test_kit/rspec/helpers/legacy.rb +228 -0
  73. data/lib/servactory/test_kit/rspec/helpers/mock_executor.rb +256 -0
  74. data/lib/servactory/test_kit/rspec/helpers/output_validator.rb +121 -0
  75. data/lib/servactory/test_kit/rspec/helpers/service_mock_builder.rb +422 -0
  76. data/lib/servactory/test_kit/rspec/helpers/service_mock_config.rb +129 -0
  77. data/lib/servactory/test_kit/rspec/helpers.rb +51 -84
  78. data/lib/servactory/test_kit/rspec/matchers/base/attribute_matcher.rb +324 -0
  79. data/lib/servactory/test_kit/rspec/matchers/base/submatcher.rb +133 -0
  80. data/lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb +101 -0
  81. data/lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb +205 -0
  82. data/lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb +100 -0
  83. data/lib/servactory/test_kit/rspec/matchers/concerns/error_message_builder.rb +106 -0
  84. data/lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb +97 -0
  85. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matcher.rb +89 -219
  86. data/lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb +74 -166
  87. data/lib/servactory/test_kit/rspec/matchers/have_service_output_matcher.rb +238 -0
  88. data/lib/servactory/test_kit/rspec/matchers/result/be_failure_service_matcher.rb +257 -0
  89. data/lib/servactory/test_kit/rspec/matchers/result/be_success_service_matcher.rb +185 -0
  90. data/lib/servactory/test_kit/rspec/matchers/submatchers/input/default_submatcher.rb +81 -0
  91. data/lib/servactory/test_kit/rspec/matchers/submatchers/input/optional_submatcher.rb +62 -0
  92. data/lib/servactory/test_kit/rspec/matchers/submatchers/input/required_submatcher.rb +93 -0
  93. data/lib/servactory/test_kit/rspec/matchers/submatchers/input/valid_with_submatcher.rb +271 -0
  94. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/consists_of_submatcher.rb +85 -0
  95. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb +120 -0
  96. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/message_submatcher.rb +115 -0
  97. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/must_submatcher.rb +82 -0
  98. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/schema_submatcher.rb +102 -0
  99. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/target_submatcher.rb +125 -0
  100. data/lib/servactory/test_kit/rspec/matchers/submatchers/shared/types_submatcher.rb +77 -0
  101. data/lib/servactory/test_kit/rspec/matchers.rb +126 -285
  102. data/lib/servactory/test_kit/utils/faker.rb +62 -2
  103. data/lib/servactory/tool_kit/dynamic_options/consists_of.rb +166 -0
  104. data/lib/servactory/tool_kit/dynamic_options/format.rb +195 -8
  105. data/lib/servactory/tool_kit/dynamic_options/inclusion.rb +219 -17
  106. data/lib/servactory/tool_kit/dynamic_options/max.rb +143 -0
  107. data/lib/servactory/tool_kit/dynamic_options/min.rb +143 -0
  108. data/lib/servactory/tool_kit/dynamic_options/multiple_of.rb +157 -8
  109. data/lib/servactory/tool_kit/dynamic_options/must.rb +194 -0
  110. data/lib/servactory/tool_kit/dynamic_options/schema.rb +226 -2
  111. data/lib/servactory/tool_kit/dynamic_options/target.rb +252 -0
  112. data/lib/servactory/version.rb +4 -4
  113. data/lib/servactory.rb +4 -0
  114. metadata +73 -19
  115. data/lib/generators/servactory/install_generator.rb +0 -21
  116. data/lib/generators/servactory/rspec_generator.rb +0 -88
  117. data/lib/generators/servactory/service_generator.rb +0 -49
  118. data/lib/servactory/configuration/setup.rb +0 -97
  119. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb +0 -68
  120. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/inclusion_matcher.rb +0 -73
  121. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/message_matcher.rb +0 -91
  122. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/must_matcher.rb +0 -72
  123. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/schema_matcher.rb +0 -92
  124. data/lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/types_matcher.rb +0 -72
  125. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/default_matcher.rb +0 -69
  126. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/optional_matcher.rb +0 -63
  127. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/required_matcher.rb +0 -81
  128. data/lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb +0 -199
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.1
4
+ version: 3.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -214,14 +214,28 @@ extra_rdoc_files: []
214
214
  files:
215
215
  - README.md
216
216
  - Rakefile
217
+ - config/locales/de.yml
217
218
  - config/locales/en.yml
219
+ - config/locales/es.yml
220
+ - config/locales/fr.yml
221
+ - config/locales/it.yml
218
222
  - config/locales/ru.yml
219
- - lib/generators/servactory/install_generator.rb
220
- - lib/generators/servactory/rspec_generator.rb
221
- - lib/generators/servactory/service_generator.rb
222
- - lib/generators/servactory/templates/services/application_service/base.rb
223
- - lib/generators/servactory/templates/services/application_service/exceptions.rb
224
- - lib/generators/servactory/templates/services/application_service/result.rb
223
+ - lib/generators/README.md
224
+ - lib/generators/servactory/base.rb
225
+ - lib/generators/servactory/extension/USAGE
226
+ - lib/generators/servactory/extension/extension_generator.rb
227
+ - lib/generators/servactory/extension/templates/extension.rb.tt
228
+ - lib/generators/servactory/install/USAGE
229
+ - lib/generators/servactory/install/install_generator.rb
230
+ - lib/generators/servactory/install/templates/application_service/base.rb.tt
231
+ - lib/generators/servactory/install/templates/application_service/exceptions.rb.tt
232
+ - lib/generators/servactory/install/templates/application_service/result.rb.tt
233
+ - lib/generators/servactory/rspec/USAGE
234
+ - lib/generators/servactory/rspec/rspec_generator.rb
235
+ - lib/generators/servactory/rspec/templates/service_spec.rb.tt
236
+ - lib/generators/servactory/service/USAGE
237
+ - lib/generators/servactory/service/service_generator.rb
238
+ - lib/generators/servactory/service/templates/service.rb.tt
225
239
  - lib/servactory.rb
226
240
  - lib/servactory/actions/action.rb
227
241
  - lib/servactory/actions/collection.rb
@@ -236,11 +250,12 @@ files:
236
250
  - lib/servactory/configuration/actions/rescue_handlers/collection.rb
237
251
  - lib/servactory/configuration/actions/shortcuts/collection.rb
238
252
  - lib/servactory/configuration/collection_mode/class_names_collection.rb
253
+ - lib/servactory/configuration/config.rb
254
+ - lib/servactory/configuration/configurable.rb
239
255
  - lib/servactory/configuration/dsl.rb
240
256
  - lib/servactory/configuration/factory.rb
241
257
  - lib/servactory/configuration/hash_mode/class_names_collection.rb
242
258
  - lib/servactory/configuration/option_helpers/option_helpers_collection.rb
243
- - lib/servactory/configuration/setup.rb
244
259
  - lib/servactory/context/callable.rb
245
260
  - lib/servactory/context/dsl.rb
246
261
  - lib/servactory/context/warehouse/base.rb
@@ -297,22 +312,60 @@ files:
297
312
  - lib/servactory/outputs/dsl.rb
298
313
  - lib/servactory/outputs/output.rb
299
314
  - lib/servactory/result.rb
315
+ - lib/servactory/stroma/dsl.rb
316
+ - lib/servactory/stroma/entry.rb
317
+ - lib/servactory/stroma/exceptions/base.rb
318
+ - lib/servactory/stroma/exceptions/invalid_hook_type.rb
319
+ - lib/servactory/stroma/exceptions/key_already_registered.rb
320
+ - lib/servactory/stroma/exceptions/registry_frozen.rb
321
+ - lib/servactory/stroma/exceptions/registry_not_finalized.rb
322
+ - lib/servactory/stroma/exceptions/unknown_hook_target.rb
323
+ - lib/servactory/stroma/hooks/applier.rb
324
+ - lib/servactory/stroma/hooks/collection.rb
325
+ - lib/servactory/stroma/hooks/factory.rb
326
+ - lib/servactory/stroma/hooks/hook.rb
327
+ - lib/servactory/stroma/registry.rb
328
+ - lib/servactory/stroma/settings/collection.rb
329
+ - lib/servactory/stroma/settings/registry_settings.rb
330
+ - lib/servactory/stroma/settings/setting.rb
331
+ - lib/servactory/stroma/state.rb
300
332
  - lib/servactory/test_kit/fake_type.rb
301
333
  - lib/servactory/test_kit/result.rb
302
334
  - lib/servactory/test_kit/rspec/helpers.rb
335
+ - lib/servactory/test_kit/rspec/helpers/argument_matchers.rb
336
+ - lib/servactory/test_kit/rspec/helpers/concerns/error_messages.rb
337
+ - lib/servactory/test_kit/rspec/helpers/concerns/service_class_validation.rb
338
+ - lib/servactory/test_kit/rspec/helpers/fluent.rb
339
+ - lib/servactory/test_kit/rspec/helpers/input_validator.rb
340
+ - lib/servactory/test_kit/rspec/helpers/legacy.rb
341
+ - lib/servactory/test_kit/rspec/helpers/mock_executor.rb
342
+ - lib/servactory/test_kit/rspec/helpers/output_validator.rb
343
+ - lib/servactory/test_kit/rspec/helpers/service_mock_builder.rb
344
+ - lib/servactory/test_kit/rspec/helpers/service_mock_config.rb
303
345
  - lib/servactory/test_kit/rspec/matchers.rb
304
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/consists_of_matcher.rb
305
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/inclusion_matcher.rb
306
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/message_matcher.rb
307
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/must_matcher.rb
308
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/schema_matcher.rb
309
- - lib/servactory/test_kit/rspec/matchers/have_service_attribute_matchers/types_matcher.rb
346
+ - lib/servactory/test_kit/rspec/matchers/base/attribute_matcher.rb
347
+ - lib/servactory/test_kit/rspec/matchers/base/submatcher.rb
348
+ - lib/servactory/test_kit/rspec/matchers/base/submatcher_context.rb
349
+ - lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb
350
+ - lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb
351
+ - lib/servactory/test_kit/rspec/matchers/concerns/error_message_builder.rb
352
+ - lib/servactory/test_kit/rspec/matchers/concerns/value_comparison.rb
310
353
  - lib/servactory/test_kit/rspec/matchers/have_service_input_matcher.rb
311
- - lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/default_matcher.rb
312
- - lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/optional_matcher.rb
313
- - lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/required_matcher.rb
314
- - lib/servactory/test_kit/rspec/matchers/have_service_input_matchers/valid_with_matcher.rb
315
354
  - lib/servactory/test_kit/rspec/matchers/have_service_internal_matcher.rb
355
+ - lib/servactory/test_kit/rspec/matchers/have_service_output_matcher.rb
356
+ - lib/servactory/test_kit/rspec/matchers/result/be_failure_service_matcher.rb
357
+ - lib/servactory/test_kit/rspec/matchers/result/be_success_service_matcher.rb
358
+ - lib/servactory/test_kit/rspec/matchers/submatchers/input/default_submatcher.rb
359
+ - lib/servactory/test_kit/rspec/matchers/submatchers/input/optional_submatcher.rb
360
+ - lib/servactory/test_kit/rspec/matchers/submatchers/input/required_submatcher.rb
361
+ - lib/servactory/test_kit/rspec/matchers/submatchers/input/valid_with_submatcher.rb
362
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/consists_of_submatcher.rb
363
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb
364
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/message_submatcher.rb
365
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/must_submatcher.rb
366
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/schema_submatcher.rb
367
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/target_submatcher.rb
368
+ - lib/servactory/test_kit/rspec/matchers/submatchers/shared/types_submatcher.rb
316
369
  - lib/servactory/test_kit/utils/faker.rb
317
370
  - lib/servactory/tool_kit/dynamic_options/consists_of.rb
318
371
  - lib/servactory/tool_kit/dynamic_options/format.rb
@@ -322,6 +375,7 @@ files:
322
375
  - lib/servactory/tool_kit/dynamic_options/multiple_of.rb
323
376
  - lib/servactory/tool_kit/dynamic_options/must.rb
324
377
  - lib/servactory/tool_kit/dynamic_options/schema.rb
378
+ - lib/servactory/tool_kit/dynamic_options/target.rb
325
379
  - lib/servactory/utils.rb
326
380
  - lib/servactory/version.rb
327
381
  homepage: https://github.com/servactory/servactory
@@ -348,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
402
  - !ruby/object:Gem::Version
349
403
  version: '0'
350
404
  requirements: []
351
- rubygems_version: 3.6.9
405
+ rubygems_version: 3.7.2
352
406
  specification_version: 4
353
407
  summary: A set of tools for building reliable services of any complexity
354
408
  test_files: []
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/base"
4
-
5
- module Servactory
6
- module Generators
7
- class InstallGenerator < Rails::Generators::Base
8
- source_root File.expand_path("templates", __dir__)
9
-
10
- def copy_services
11
- directory "services/application_service", "app/services/application_service"
12
- end
13
-
14
- def copy_locales
15
- %i[en ru].each do |locale|
16
- copy_file "../../../../config/locales/#{locale}.yml", "config/locales/servactory.#{locale}.yml"
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/named_base"
4
-
5
- module Servactory
6
- module Generators
7
- class RspecGenerator < Rails::Generators::NamedBase
8
- source_root File.expand_path("templates", __dir__)
9
-
10
- argument :attributes, type: :array, default: [], banner: "input_name"
11
-
12
- def create_service
13
- create_file "app/services/#{file_path}_spec.rb" do
14
- <<~RUBY
15
- # frozen_string_literal: true
16
-
17
- RSpec.describe #{class_name}, type: :service do
18
- pending "add some examples to (or delete) \#{__FILE__}"
19
-
20
- # let(:attributes) do
21
- # {
22
- #{input_attribute_draw}
23
- # }
24
- # end
25
- #
26
- #{input_let_draw}
27
- #
28
- # describe "validation" do
29
- # describe "inputs" do
30
- #{input_validation_draw}
31
- # end
32
- #
33
- # describe "internals" do
34
- # it { expect { perform }.to have_internal(:some_data).type(String) }
35
- # end
36
- # end
37
- #
38
- # describe ".call!" do
39
- # subject(:perform) { described_class.call!(**attributes) }
40
- #
41
- # describe "and the data required for work is also valid" do
42
- # it { expect(perform).to be_success_service }
43
- #
44
- # # ...
45
- # end
46
- #
47
- # describe "but the data required for work is invalid" do
48
- # # Provide a reason why the data is invalid and then use this:
49
- # it { expect(perform).to be_failure_service }
50
- #
51
- # # ...
52
- # end
53
- # end
54
- end
55
- RUBY
56
- end
57
- end
58
-
59
- def input_attribute_draw
60
- input_names.map do |input_name|
61
- <<~RUBY.strip
62
- # #{input_name}: #{input_name}
63
- RUBY
64
- end.join(",\n ")
65
- end
66
-
67
- def input_let_draw
68
- input_names.map do |input_name|
69
- <<~RUBY.strip
70
- # let(:#{input_name}) { "Some value" }
71
- RUBY
72
- end.join("\n ")
73
- end
74
-
75
- def input_validation_draw
76
- input_names.map do |input_name|
77
- <<~RUBY.strip
78
- # it { expect { perform }.to have_input(:#{input_name}).valid_with(attributes).type(String).required }
79
- RUBY
80
- end.join("\n ")
81
- end
82
-
83
- def input_names
84
- @input_names ||= attributes_names
85
- end
86
- end
87
- end
88
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/named_base"
4
-
5
- module Servactory
6
- module Generators
7
- class ServiceGenerator < Rails::Generators::NamedBase
8
- source_root File.expand_path("templates", __dir__)
9
-
10
- argument :attributes, type: :array, default: [], banner: "input_name"
11
-
12
- def create_service # rubocop:disable Metrics/MethodLength
13
- create_file "app/services/#{file_path}.rb" do
14
- <<~RUBY
15
- # frozen_string_literal: true
16
-
17
- class #{class_name} < ApplicationService::Base
18
- #{input_draw}
19
-
20
- output :result, type: Symbol
21
-
22
- make :something
23
-
24
- private
25
-
26
- def something
27
- # Write your code here
28
-
29
- outputs.result = :done
30
- end
31
- end
32
- RUBY
33
- end
34
- end
35
-
36
- def input_draw
37
- input_names.map do |input_name|
38
- <<~RUBY.squish
39
- input :#{input_name}, type: String
40
- RUBY
41
- end.join("\n ")
42
- end
43
-
44
- def input_names
45
- @input_names ||= attributes_names
46
- end
47
- end
48
- end
49
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Configuration
5
- class Setup
6
- attr_accessor :input_exception_class,
7
- :internal_exception_class,
8
- :output_exception_class,
9
- :success_class,
10
- :failure_class,
11
- :result_class,
12
- :collection_mode_class_names,
13
- :hash_mode_class_names,
14
- :input_option_helpers,
15
- :internal_option_helpers,
16
- :output_option_helpers,
17
- :action_aliases,
18
- :action_shortcuts,
19
- :action_rescue_handlers,
20
- :i18n_root_key,
21
- :predicate_methods_enabled
22
-
23
- def initialize # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
24
- @input_exception_class = Servactory::Exceptions::Input
25
- @internal_exception_class = Servactory::Exceptions::Internal
26
- @output_exception_class = Servactory::Exceptions::Output
27
-
28
- @success_class = Servactory::Exceptions::Success
29
- @failure_class = Servactory::Exceptions::Failure
30
-
31
- @result_class = Servactory::Result
32
-
33
- @collection_mode_class_names =
34
- Servactory::Configuration::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
35
-
36
- @hash_mode_class_names =
37
- Servactory::Configuration::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
38
-
39
- @input_option_helpers =
40
- Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_input_option_helpers)
41
-
42
- @internal_option_helpers =
43
- Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_internal_option_helpers)
44
-
45
- @output_option_helpers =
46
- Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_output_option_helpers)
47
-
48
- @action_aliases = Servactory::Configuration::Actions::Aliases::Collection.new
49
- @action_shortcuts = Servactory::Configuration::Actions::Shortcuts::Collection.new
50
- @action_rescue_handlers = Servactory::Configuration::Actions::RescueHandlers::Collection.new
51
-
52
- @i18n_root_key = "servactory"
53
-
54
- @predicate_methods_enabled = true
55
- end
56
-
57
- def predicate_methods_enabled?
58
- @predicate_methods_enabled
59
- end
60
-
61
- private
62
-
63
- def default_collection_mode_class_names
64
- Set[Array, Set]
65
- end
66
-
67
- def default_hash_mode_class_names
68
- Set[Hash]
69
- end
70
-
71
- def default_input_option_helpers
72
- Set[
73
- Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
74
- Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
75
- Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
76
- Servactory::ToolKit::DynamicOptions::Inclusion.use
77
- ]
78
- end
79
-
80
- def default_internal_option_helpers
81
- Set[
82
- Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
83
- Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
84
- Servactory::ToolKit::DynamicOptions::Inclusion.use
85
- ]
86
- end
87
-
88
- def default_output_option_helpers
89
- Set[
90
- Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names:),
91
- Servactory::ToolKit::DynamicOptions::Schema.use(default_hash_mode_class_names:),
92
- Servactory::ToolKit::DynamicOptions::Inclusion.use
93
- ]
94
- end
95
- end
96
- end
97
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module TestKit
5
- module Rspec
6
- module Matchers
7
- module HaveServiceAttributeMatchers
8
- class ConsistsOfMatcher
9
- OPTION_NAME = :consists_of
10
- OPTION_BODY_KEY = :type
11
-
12
- attr_reader :missing_option
13
-
14
- def initialize(described_class, attribute_type, attribute_name, option_types, consists_of_types)
15
- @described_class = described_class
16
- @attribute_type = attribute_type
17
- @attribute_type_plural = attribute_type.to_s.pluralize.to_sym
18
- @attribute_name = attribute_name
19
- @option_types = option_types
20
- @consists_of_types = consists_of_types
21
-
22
- @attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
23
-
24
- @missing_option = ""
25
- end
26
-
27
- def description
28
- result = "consists_of: "
29
- result + consists_of_types.join(", ")
30
- end
31
-
32
- def matches?(subject)
33
- if submatcher_passes?(subject)
34
- true
35
- else
36
- @missing_option = build_missing_option
37
-
38
- false
39
- end
40
- end
41
-
42
- private
43
-
44
- attr_reader :described_class,
45
- :attribute_type,
46
- :attribute_type_plural,
47
- :attribute_name,
48
- :option_types,
49
- :consists_of_types,
50
- :attribute_data
51
-
52
- def submatcher_passes?(_subject)
53
- attribute_consists_of = attribute_data.fetch(OPTION_NAME)
54
- attribute_consists_of_types = Array(attribute_consists_of.fetch(OPTION_BODY_KEY))
55
-
56
- attribute_consists_of_types.difference(consists_of_types).empty? &&
57
- consists_of_types.difference(attribute_consists_of_types).empty?
58
- end
59
-
60
- def build_missing_option
61
- "should be consists_of"
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module TestKit
5
- module Rspec
6
- module Matchers
7
- module HaveServiceAttributeMatchers
8
- class InclusionMatcher
9
- OPTION_NAME = :inclusion
10
- OPTION_BODY_KEY = :in
11
-
12
- attr_reader :missing_option
13
-
14
- def initialize(described_class, attribute_type, attribute_name, values)
15
- @described_class = described_class
16
- @attribute_type = attribute_type
17
- @attribute_type_plural = attribute_type.to_s.pluralize.to_sym
18
- @attribute_name = attribute_name
19
- @values = values
20
-
21
- @attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
22
-
23
- @missing_option = ""
24
- end
25
-
26
- def description
27
- "inclusion: #{values.join(', ')}"
28
- end
29
-
30
- def matches?(subject)
31
- if submatcher_passes?(subject)
32
- true
33
- else
34
- @missing_option = build_missing_option
35
-
36
- false
37
- end
38
- end
39
-
40
- private
41
-
42
- attr_reader :described_class,
43
- :attribute_type,
44
- :attribute_type_plural,
45
- :attribute_name,
46
- :values,
47
- :attribute_data
48
-
49
- def submatcher_passes?(_subject)
50
- attribute_inclusion = attribute_data.fetch(OPTION_NAME)
51
- attribute_inclusion_in = attribute_inclusion.fetch(OPTION_BODY_KEY)
52
-
53
- attribute_inclusion_in.difference(values).empty? &&
54
- values.difference(attribute_inclusion_in).empty?
55
- end
56
-
57
- def build_missing_option
58
- attribute_inclusion = attribute_data.fetch(OPTION_NAME)
59
- attribute_inclusion_in = attribute_inclusion.fetch(OPTION_BODY_KEY)
60
-
61
- <<~MESSAGE
62
- should include the expected values
63
-
64
- expected #{values.inspect}
65
- got #{attribute_inclusion_in.inspect}
66
- MESSAGE
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module TestKit
5
- module Rspec
6
- module Matchers
7
- module HaveServiceAttributeMatchers
8
- class MessageMatcher
9
- attr_reader :missing_option
10
-
11
- def initialize(described_class, attribute_type, attribute_name, submatcher, custom_message)
12
- @described_class = described_class
13
- @attribute_type = attribute_type
14
- @attribute_type_plural = attribute_type.to_s.pluralize.to_sym
15
- @attribute_name = attribute_name
16
- @custom_message = custom_message
17
-
18
- attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
19
-
20
- attribute_schema = attribute_data.fetch(submatcher.class::OPTION_NAME)
21
- @attribute_schema_is = attribute_schema.fetch(submatcher.class::OPTION_BODY_KEY)
22
- @attribute_schema_message = attribute_schema.fetch(:message)
23
-
24
- @missing_option = ""
25
- end
26
-
27
- def description
28
- result = "message: "
29
- result + attribute_schema_message
30
- end
31
-
32
- def matches?(subject)
33
- if submatcher_passes?(subject)
34
- true
35
- else
36
- @missing_option = build_missing_option
37
-
38
- false
39
- end
40
- end
41
-
42
- private
43
-
44
- attr_reader :described_class,
45
- :attribute_type,
46
- :attribute_type_plural,
47
- :attribute_name,
48
- :option_types,
49
- :custom_message,
50
- :attribute_schema_is,
51
- :attribute_schema_message
52
-
53
- def submatcher_passes?(_subject)
54
- schema_message_equal?
55
- end
56
-
57
- def schema_message_equal? # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
58
- @schema_message_equal ||=
59
- if custom_message.present? && !attribute_schema_message.nil?
60
- if custom_message.is_a?(RSpec::Matchers::BuiltIn::BaseMatcher)
61
- RSpec::Expectations::ValueExpectationTarget
62
- .new(attribute_schema_message)
63
- .to(custom_message)
64
-
65
- true
66
- elsif attribute_schema_message.is_a?(Proc)
67
- attribute_schema_message.call.casecmp(custom_message).zero?
68
- else
69
- attribute_schema_message.casecmp(custom_message).zero?
70
- end
71
- else
72
- true
73
- end
74
- end
75
-
76
- def build_missing_option
77
- unless schema_message_equal? # rubocop:disable Style/GuardClause
78
- <<~MESSAGE
79
- should return expected message in case of problem:
80
-
81
- expected #{attribute_schema_message.inspect}
82
- got #{custom_message.inspect}
83
- MESSAGE
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end