convenient_service 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/convenient_service/commands/is_service.rb +28 -0
- data/lib/convenient_service/commands/is_service_class.rb +30 -0
- data/lib/convenient_service/commands.rb +4 -0
- data/lib/convenient_service/common/plugins.rb +2 -3
- data/lib/convenient_service/core/concern/class_methods.rb +3 -0
- data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +22 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb +1 -1
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/observable/entities/event.rb +13 -15
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands/normalize_env.rb +55 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands.rb +1 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern/instance_methods.rb +3 -3
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/classic.rb +14 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +22 -0
- data/lib/convenient_service/dependencies/built_in.rb +0 -7
- data/lib/convenient_service/dependencies/extractions/ds.rb +45 -0
- data/lib/convenient_service/dependencies/only_queries.rb +29 -0
- data/lib/convenient_service/dependencies/queries/gems/active_model.rb +38 -0
- data/lib/convenient_service/dependencies/queries/gems/logger.rb +39 -0
- data/lib/convenient_service/dependencies/queries/gems/paint.rb +39 -0
- data/lib/convenient_service/dependencies/queries/gems/rspec.rb +60 -0
- data/lib/convenient_service/dependencies/queries/ruby.rb +103 -0
- data/lib/convenient_service/dependencies/queries/version/null_version.rb +87 -0
- data/lib/convenient_service/dependencies/queries/version.rb +87 -0
- data/lib/convenient_service/dependencies/queries.rb +536 -0
- data/lib/convenient_service/dependencies.rb +2 -438
- data/lib/convenient_service/feature/configs/standard.rb +0 -2
- data/lib/convenient_service/service/configs/amazing_print_inspect/aliases.rb +7 -0
- data/lib/convenient_service/service/configs/amazing_print_inspect.rb +61 -0
- data/lib/convenient_service/service/configs/awesome_print_inspect.rb +1 -1
- data/lib/convenient_service/service/configs/{minimal.rb → essential.rb} +2 -107
- data/lib/convenient_service/service/configs/standard/v1.rb +5 -10
- data/lib/convenient_service/service/configs/standard.rb +19 -31
- data/lib/convenient_service/service/configs.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/and.rb +4 -1
- data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/empty.rb +4 -4
- data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb +7 -0
- data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +18 -0
- data/lib/convenient_service/service/plugins/can_have_fallbacks/exceptions.rb +22 -4
- data/lib/convenient_service/service/plugins/can_have_fallbacks/middleware.rb +3 -3
- data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +66 -0
- data/lib/convenient_service/service/plugins/can_have_rollbacks.rb +3 -0
- data/lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb +7 -0
- data/lib/convenient_service/service/plugins/can_have_steps/commands/is_step.rb +34 -0
- data/lib/convenient_service/service/plugins/can_have_steps/commands.rb +1 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +22 -14
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_method_step/can_be_executed/middleware.rb +1 -15
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/exceptions.rb +53 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/middleware.rb +60 -15
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks.rb +1 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect/concern.rb +3 -2
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/middleware.rb +26 -1
- data/lib/convenient_service/service/plugins/can_have_steps.rb +41 -0
- data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +2 -2
- data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +53 -0
- data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +108 -0
- data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments.rb +4 -0
- data/lib/convenient_service/service/plugins/has_amazing_print_inspect/concern.rb +39 -0
- data/lib/convenient_service/service/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +32 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_step/concern.rb +7 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect/concern.rb +41 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_awesome_print_inspect/concern.rb +2 -2
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb +0 -140
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb +161 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/exceptions.rb +34 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects.rb +4 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/has_mermaid_flowchart/concern.rb +6 -1
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +1 -0
- data/lib/convenient_service/service/plugins.rb +3 -1
- data/lib/convenient_service/support/counter.rb +2 -0
- data/lib/convenient_service/support/middleware/stack_builder.rb +37 -0
- data/lib/convenient_service/support/thread_safe_counter.rb +1 -0
- data/lib/convenient_service/support.rb +0 -3
- data/lib/convenient_service/utils/object/get_own_method.rb +54 -0
- data/lib/convenient_service/utils/object/safe_send.rb +84 -0
- data/lib/convenient_service/utils/object.rb +24 -0
- data/lib/convenient_service/utils/string/enclose.rb +52 -0
- data/lib/convenient_service/utils/string.rb +5 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +62 -0
- metadata +149 -16
- data/lib/convenient_service/common/plugins/normalizes_env/middleware.rb +0 -31
- data/lib/convenient_service/common/plugins/normalizes_env.rb +0 -3
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/result.rb +0 -3
- data/lib/convenient_service/services.rb +0 -4
- data/lib/convenient_service/support/gems/active_model.rb +0 -36
- data/lib/convenient_service/support/gems/logger.rb +0 -37
- data/lib/convenient_service/support/gems/paint.rb +0 -37
- data/lib/convenient_service/support/gems/rspec.rb +0 -58
- data/lib/convenient_service/support/ruby.rb +0 -53
- data/lib/convenient_service/support/version/null_version.rb +0 -85
- data/lib/convenient_service/support/version.rb +0 -75
- /data/lib/convenient_service/{support → dependencies/queries}/gems.rb +0 -0
@@ -4,34 +4,14 @@ module ConvenientService
|
|
4
4
|
module Service
|
5
5
|
module Configs
|
6
6
|
##
|
7
|
-
# Defines
|
7
|
+
# Defines essential configuration that adds a constructor, JSend-inspired result, steps, basic inspects, and internals to services.
|
8
8
|
#
|
9
9
|
# @note This config is NOT intented for the end-user usage. Use `Standard` instead.
|
10
10
|
#
|
11
|
-
# @note
|
12
|
-
# `use ConvenientService::Plugins::Common::NormalizesEnv::Middleware` should be used in a config that has the first `concern` that introduces a method.
|
13
|
-
# For example, `:result` is added by `use ConvenientService::Plugins::Service::HasJSendResult::Concern` in `Minimal`.
|
14
|
-
# That is why the following code is written in the `Minimal` config.
|
15
|
-
#
|
16
|
-
# middlewares :result do
|
17
|
-
# use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
18
|
-
#
|
19
|
-
# # ...
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# In turn, `:fallback_result` is added by `use ConvenientService::Plugins::Service::CanHaveFallbacks::Concern` in `Standard`.
|
23
|
-
# That is why it is the responsibility of the `Standard` config, to define:
|
24
|
-
#
|
25
|
-
# middlewares :fallback_result do
|
26
|
-
# use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
27
|
-
#
|
28
|
-
# # ...
|
29
|
-
# end
|
30
|
-
#
|
31
11
|
# @internal
|
32
12
|
# NOTE: Heavily used in specs to test concerns and middlewares in isolation.
|
33
13
|
#
|
34
|
-
module
|
14
|
+
module Essential
|
35
15
|
include Support::Concern
|
36
16
|
|
37
17
|
##
|
@@ -66,15 +46,7 @@ module ConvenientService
|
|
66
46
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Concern
|
67
47
|
end
|
68
48
|
|
69
|
-
##
|
70
|
-
# TODO: Move `NormalizesEnv` inside `Core`.
|
71
|
-
#
|
72
|
-
middlewares :initialize do
|
73
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
74
|
-
end
|
75
|
-
|
76
49
|
middlewares :result do
|
77
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
78
50
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
79
51
|
|
80
52
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware
|
@@ -82,59 +54,27 @@ module ConvenientService
|
|
82
54
|
use ConvenientService::Plugins::Service::CanHaveConnectedSteps::Middleware
|
83
55
|
end
|
84
56
|
|
85
|
-
middlewares :step do
|
86
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
87
|
-
end
|
88
|
-
|
89
|
-
middlewares :success do
|
90
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
91
|
-
end
|
92
|
-
|
93
|
-
middlewares :failure do
|
94
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
95
|
-
end
|
96
|
-
|
97
|
-
middlewares :error do
|
98
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
99
|
-
end
|
100
|
-
|
101
|
-
middlewares :result, scope: :class do
|
102
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
103
|
-
end
|
104
|
-
|
105
57
|
middlewares :step, scope: :class do
|
106
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
107
|
-
|
108
58
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
109
59
|
end
|
110
60
|
|
111
61
|
middlewares :not_step, scope: :class do
|
112
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
113
|
-
|
114
62
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
115
63
|
end
|
116
64
|
|
117
65
|
middlewares :and_step, scope: :class do
|
118
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
119
|
-
|
120
66
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
121
67
|
end
|
122
68
|
|
123
69
|
middlewares :and_not_step, scope: :class do
|
124
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
125
|
-
|
126
70
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
127
71
|
end
|
128
72
|
|
129
73
|
middlewares :or_step, scope: :class do
|
130
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
131
|
-
|
132
74
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
133
75
|
end
|
134
76
|
|
135
77
|
middlewares :or_not_step, scope: :class do
|
136
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
137
|
-
|
138
78
|
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
|
139
79
|
end
|
140
80
|
|
@@ -163,27 +103,9 @@ module ConvenientService
|
|
163
103
|
end
|
164
104
|
|
165
105
|
middlewares :initialize do
|
166
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
167
|
-
|
168
106
|
use ConvenientService::Plugins::Result::HasJSendStatusAndAttributes::Middleware
|
169
107
|
end
|
170
108
|
|
171
|
-
middlewares :data do
|
172
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
173
|
-
end
|
174
|
-
|
175
|
-
middlewares :message do
|
176
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
177
|
-
end
|
178
|
-
|
179
|
-
middlewares :code do
|
180
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
181
|
-
end
|
182
|
-
|
183
|
-
middlewares :to_kwargs do
|
184
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
185
|
-
end
|
186
|
-
|
187
109
|
class self::Data
|
188
110
|
include Core
|
189
111
|
|
@@ -217,30 +139,6 @@ module ConvenientService
|
|
217
139
|
use ConvenientService::Plugins::Status::HasInspect::Concern
|
218
140
|
end
|
219
141
|
|
220
|
-
middlewares :success? do
|
221
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
222
|
-
end
|
223
|
-
|
224
|
-
middlewares :failure? do
|
225
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
226
|
-
end
|
227
|
-
|
228
|
-
middlewares :error? do
|
229
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
230
|
-
end
|
231
|
-
|
232
|
-
middlewares :not_success? do
|
233
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
234
|
-
end
|
235
|
-
|
236
|
-
middlewares :not_failure? do
|
237
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
238
|
-
end
|
239
|
-
|
240
|
-
middlewares :not_error? do
|
241
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
242
|
-
end
|
243
|
-
|
244
142
|
class self::Internals
|
245
143
|
include Core
|
246
144
|
|
@@ -278,7 +176,6 @@ module ConvenientService
|
|
278
176
|
# TODO: Simple debug for middlewares. For one service only.
|
279
177
|
#
|
280
178
|
middlewares :result do
|
281
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
282
179
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
283
180
|
|
284
181
|
use ConvenientService::Plugins::Step::HasResult::Middleware
|
@@ -292,8 +189,6 @@ module ConvenientService
|
|
292
189
|
# TODO: Rename.
|
293
190
|
#
|
294
191
|
middlewares :printable_service do
|
295
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
296
|
-
|
297
192
|
use ConvenientService::Plugins::Step::CanBeMethodStep::CanBePrinted::Middleware
|
298
193
|
end
|
299
194
|
|
@@ -20,7 +20,7 @@ module ConvenientService
|
|
20
20
|
#
|
21
21
|
# rubocop:disable Lint/ConstantDefinitionInBlock
|
22
22
|
included do
|
23
|
-
include Configs::
|
23
|
+
include Configs::Essential
|
24
24
|
|
25
25
|
concerns do
|
26
26
|
use ConvenientService::Plugins::Common::CachesConstructorArguments::Concern
|
@@ -50,9 +50,7 @@ module ConvenientService
|
|
50
50
|
end
|
51
51
|
|
52
52
|
middlewares :result do
|
53
|
-
|
54
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
55
|
-
ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
53
|
+
unshift ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
56
54
|
|
57
55
|
insert_before \
|
58
56
|
ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware,
|
@@ -98,6 +96,7 @@ module ConvenientService
|
|
98
96
|
use ConvenientService::Plugins::Common::HasJSendResultDuckShortSyntax::Concern
|
99
97
|
use ConvenientService::Plugins::Result::CanRecalculateResult::Concern
|
100
98
|
|
99
|
+
use ConvenientService::Plugins::Result::CanBeFromException::Concern
|
101
100
|
use ConvenientService::Plugins::Result::CanBeOwnResult::Concern
|
102
101
|
use ConvenientService::Plugins::Result::CanHaveParentResult::Concern
|
103
102
|
use ConvenientService::Plugins::Result::CanHaveCheckedStatus::Concern
|
@@ -162,9 +161,7 @@ module ConvenientService
|
|
162
161
|
end
|
163
162
|
|
164
163
|
middlewares :result do
|
165
|
-
|
166
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
167
|
-
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
164
|
+
unshift ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
168
165
|
|
169
166
|
insert_before \
|
170
167
|
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware,
|
@@ -172,9 +169,7 @@ module ConvenientService
|
|
172
169
|
end
|
173
170
|
|
174
171
|
middlewares :result, scope: :class do
|
175
|
-
|
176
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
177
|
-
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
172
|
+
unshift ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
178
173
|
|
179
174
|
insert_before \
|
180
175
|
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware,
|
@@ -22,7 +22,7 @@ module ConvenientService
|
|
22
22
|
#
|
23
23
|
# rubocop:disable Lint/ConstantDefinitionInBlock
|
24
24
|
included do
|
25
|
-
include Configs::
|
25
|
+
include Configs::Essential
|
26
26
|
|
27
27
|
concerns do
|
28
28
|
use ConvenientService::Plugins::Common::CachesConstructorArguments::Concern
|
@@ -43,9 +43,7 @@ module ConvenientService
|
|
43
43
|
end
|
44
44
|
|
45
45
|
middlewares :result do
|
46
|
-
|
47
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
48
|
-
ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
46
|
+
unshift ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
49
47
|
|
50
48
|
insert_before \
|
51
49
|
ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware,
|
@@ -65,12 +63,7 @@ module ConvenientService
|
|
65
63
|
ConvenientService::Plugins::Service::SetsParentToForeignResult::Middleware
|
66
64
|
end
|
67
65
|
|
68
|
-
##
|
69
|
-
# @internal
|
70
|
-
# NOTE: Check `Minimal` docs to understand why `use ConvenientService::Plugins::Common::NormalizesEnv::Middleware` for `:fallback_failure_result` is used in `Standard`, not in `Minimal` config.
|
71
|
-
#
|
72
66
|
middlewares :fallback_failure_result do
|
73
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
74
67
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
75
68
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
76
69
|
|
@@ -78,12 +71,7 @@ module ConvenientService
|
|
78
71
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: :failure)
|
79
72
|
end
|
80
73
|
|
81
|
-
##
|
82
|
-
# @internal
|
83
|
-
# NOTE: Check `Minimal` docs to understand why `use ConvenientService::Plugins::Common::NormalizesEnv::Middleware` for `:fallback_error_result` is used in `Standard`, not in `Minimal` config.
|
84
|
-
#
|
85
74
|
middlewares :fallback_error_result do
|
86
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
87
75
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
88
76
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
89
77
|
|
@@ -91,12 +79,15 @@ module ConvenientService
|
|
91
79
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: :error)
|
92
80
|
end
|
93
81
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
82
|
+
middlewares :fallback_result do
|
83
|
+
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
84
|
+
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
85
|
+
|
86
|
+
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware
|
87
|
+
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: nil)
|
88
|
+
end
|
89
|
+
|
98
90
|
middlewares :negated_result do
|
99
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
100
91
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware
|
101
92
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware
|
102
93
|
|
@@ -108,7 +99,7 @@ module ConvenientService
|
|
108
99
|
# `after :step do |step|` is executed after step result is calculated.
|
109
100
|
# This completely makes sence and is useful for debugging for example.
|
110
101
|
#
|
111
|
-
# But `before :step do` is
|
102
|
+
# But `before :step do` is also executed after step result is calculated.
|
112
103
|
# That confuses the end-users a lot.
|
113
104
|
# Probably a dedicated plugin is needed?
|
114
105
|
# Or to forbid `before :step do`?
|
@@ -136,6 +127,7 @@ module ConvenientService
|
|
136
127
|
use ConvenientService::Plugins::Result::CanRecalculateResult::Concern
|
137
128
|
|
138
129
|
use ConvenientService::Plugins::Result::HasNegatedResult::Concern
|
130
|
+
use ConvenientService::Plugins::Result::CanBeFromException::Concern
|
139
131
|
use ConvenientService::Plugins::Result::CanBeOwnResult::Concern
|
140
132
|
use ConvenientService::Plugins::Result::CanHaveFallbacks::Concern
|
141
133
|
use ConvenientService::Plugins::Result::CanHaveParentResult::Concern
|
@@ -155,8 +147,6 @@ module ConvenientService
|
|
155
147
|
end
|
156
148
|
|
157
149
|
middlewares :negated_result do
|
158
|
-
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
|
159
|
-
|
160
150
|
use ConvenientService::Plugins::Common::EnsuresNegatedJSendResult::Middleware
|
161
151
|
end
|
162
152
|
|
@@ -198,23 +188,23 @@ module ConvenientService
|
|
198
188
|
end
|
199
189
|
|
200
190
|
middlewares :result do
|
201
|
-
use ConvenientService::Plugins::Step::CanHaveFallbacks::Middleware.with(fallback_true_status: :failure)
|
202
|
-
|
203
191
|
insert_after \
|
204
192
|
ConvenientService::Plugins::Step::HasResult::Middleware,
|
205
193
|
ConvenientService::Plugins::Step::CanHaveParentResult::Middleware
|
194
|
+
|
195
|
+
insert_after \
|
196
|
+
ConvenientService::Plugins::Step::HasResult::Middleware,
|
197
|
+
ConvenientService::Plugins::Step::CanHaveFallbacks::Middleware.with(fallback_true_status: :failure)
|
206
198
|
end
|
207
199
|
end
|
208
200
|
|
209
201
|
if Dependencies.rspec.loaded?
|
210
202
|
concerns do
|
211
|
-
|
203
|
+
unshift ConvenientService::Plugins::Service::CanHaveStubbedResults::Concern
|
212
204
|
end
|
213
205
|
|
214
206
|
middlewares :result do
|
215
|
-
|
216
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
217
|
-
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
207
|
+
unshift ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
218
208
|
|
219
209
|
insert_before \
|
220
210
|
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware,
|
@@ -222,9 +212,7 @@ module ConvenientService
|
|
222
212
|
end
|
223
213
|
|
224
214
|
middlewares :result, scope: :class do
|
225
|
-
|
226
|
-
ConvenientService::Plugins::Common::NormalizesEnv::Middleware,
|
227
|
-
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
215
|
+
unshift ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware
|
228
216
|
|
229
217
|
insert_before \
|
230
218
|
ConvenientService::Plugins::Service::CanHaveStubbedResults::Middleware,
|
data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/empty.rb
CHANGED
@@ -17,28 +17,28 @@ module ConvenientService
|
|
17
17
|
# @raise [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoResult]
|
18
18
|
#
|
19
19
|
def result
|
20
|
-
raise Exceptions::EmptyExpressionHasNoResult.new
|
20
|
+
::ConvenientService.raise Exceptions::EmptyExpressionHasNoResult.new
|
21
21
|
end
|
22
22
|
|
23
23
|
##
|
24
24
|
# @raise [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoStatus]
|
25
25
|
#
|
26
26
|
def success?
|
27
|
-
raise Exceptions::EmptyExpressionHasNoStatus.new
|
27
|
+
::ConvenientService.raise Exceptions::EmptyExpressionHasNoStatus.new
|
28
28
|
end
|
29
29
|
|
30
30
|
##
|
31
31
|
# @raise [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoStatus]
|
32
32
|
#
|
33
33
|
def failure?
|
34
|
-
raise Exceptions::EmptyExpressionHasNoStatus.new
|
34
|
+
::ConvenientService.raise Exceptions::EmptyExpressionHasNoStatus.new
|
35
35
|
end
|
36
36
|
|
37
37
|
##
|
38
38
|
# @raise [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoStatus]
|
39
39
|
#
|
40
40
|
def error?
|
41
|
-
raise Exceptions::EmptyExpressionHasNoStatus.new
|
41
|
+
::ConvenientService.raise Exceptions::EmptyExpressionHasNoStatus.new
|
42
42
|
end
|
43
43
|
|
44
44
|
##
|
data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb
CHANGED
@@ -56,6 +56,13 @@ module ConvenientService
|
|
56
56
|
@steps = steps
|
57
57
|
end
|
58
58
|
|
59
|
+
##
|
60
|
+
# @return [Integer]
|
61
|
+
#
|
62
|
+
def size
|
63
|
+
steps.size
|
64
|
+
end
|
65
|
+
|
59
66
|
##
|
60
67
|
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
61
68
|
# @raise [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoResult]
|
@@ -25,6 +25,15 @@ module ConvenientService
|
|
25
25
|
def fallback_error_result
|
26
26
|
::ConvenientService.raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: :error)
|
27
27
|
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Returns `ConvenientService::Service::Plugins::HasJSendResult::Entities::Result` when overridden.
|
31
|
+
#
|
32
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden]
|
33
|
+
#
|
34
|
+
def fallback_result
|
35
|
+
::ConvenientService.raise Exceptions::FallbackResultIsNotOverridden.new(service: self, status: nil)
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
class_methods do
|
@@ -97,6 +106,15 @@ module ConvenientService
|
|
97
106
|
def fallback_error_result(...)
|
98
107
|
new(...).fallback_error_result
|
99
108
|
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Returns `ConvenientService::Service::Plugins::HasJSendResult::Entities::Result` when `#fallback_result` is overridden.
|
112
|
+
#
|
113
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden]
|
114
|
+
#
|
115
|
+
def fallback_result(...)
|
116
|
+
new(...).fallback_result
|
117
|
+
end
|
100
118
|
end
|
101
119
|
end
|
102
120
|
end
|
@@ -8,26 +8,44 @@ module ConvenientService
|
|
8
8
|
class FallbackResultIsNotOverridden < ::ConvenientService::Exception
|
9
9
|
def initialize_with_kwargs(service:, status:)
|
10
10
|
message = <<~TEXT
|
11
|
-
Fallback
|
11
|
+
Fallback#{enclose(status, " ")}result method (#fallback#{enclose(status, "_")}result) of `#{service.class}` is NOT overridden.
|
12
12
|
|
13
|
-
NOTE: Make sure overridden `
|
13
|
+
NOTE: Make sure overridden `fallback#{enclose(status, "_")}result` returns `success` with reasonable "null" data.
|
14
14
|
TEXT
|
15
15
|
|
16
16
|
initialize(message)
|
17
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
def enclose(...)
|
25
|
+
ConvenientService::Utils::String.enclose(...)
|
26
|
+
end
|
18
27
|
end
|
19
28
|
|
20
29
|
class ServiceFallbackReturnValueNotSuccess < ::ConvenientService::Exception
|
21
30
|
def initialize_with_kwargs(service:, result:, status:)
|
22
31
|
message = <<~TEXT
|
23
|
-
Return value of service `#{service.class}
|
32
|
+
Return value of service `#{service.class}`#{enclose(status, " ")}fallback is NOT a `success`.
|
24
33
|
It is `#{result.status}`.
|
25
34
|
|
26
|
-
Did you accidentally call `failure` or `error` instead of `success` from the `
|
35
|
+
Did you accidentally call `failure` or `error` instead of `success` from the `fallback#{enclose(status, "_")}result` method?
|
27
36
|
TEXT
|
28
37
|
|
29
38
|
initialize(message)
|
30
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
##
|
44
|
+
# @return [String]
|
45
|
+
#
|
46
|
+
def enclose(...)
|
47
|
+
ConvenientService::Utils::String.enclose(...)
|
48
|
+
end
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
@@ -5,12 +5,12 @@ module ConvenientService
|
|
5
5
|
module Plugins
|
6
6
|
module CanHaveFallbacks
|
7
7
|
class Middleware < MethodChainMiddleware
|
8
|
-
intended_for [:fallback_failure_result, :fallback_error_result], entity: :service
|
8
|
+
intended_for [:fallback_failure_result, :fallback_error_result, :fallback_result], entity: :service
|
9
9
|
|
10
10
|
##
|
11
11
|
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
12
12
|
#
|
13
|
-
# @note Both `fallback_failure_result` and `
|
13
|
+
# @note Both `fallback_failure_result`, `fallback_error_result` and `fallback_result` are always successful, that is why their statuses are pre-checked.
|
14
14
|
#
|
15
15
|
def next(...)
|
16
16
|
fallback_result = chain.next(...)
|
@@ -24,7 +24,7 @@ module ConvenientService
|
|
24
24
|
private
|
25
25
|
|
26
26
|
##
|
27
|
-
# @return [Symbol]
|
27
|
+
# @return [Symbol, nil]
|
28
28
|
#
|
29
29
|
def status
|
30
30
|
middleware_arguments.kwargs.fetch(:status)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module CanHaveRollbacks
|
7
|
+
class Middleware < MethodChainMiddleware
|
8
|
+
intended_for :result, entity: :service
|
9
|
+
|
10
|
+
##
|
11
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
12
|
+
#
|
13
|
+
def next(...)
|
14
|
+
result = chain.next(...)
|
15
|
+
|
16
|
+
rollback_result(result) if result.status.unsafe_not_success?
|
17
|
+
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
##
|
24
|
+
# @param result [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
25
|
+
# @return [void]
|
26
|
+
#
|
27
|
+
# @internal
|
28
|
+
# IMPORTANT: Uses recursion inside `rollback_organizer`. Recursion has two exit conditions. When service has no steps. When service has only method steps.
|
29
|
+
#
|
30
|
+
def rollback_result(result)
|
31
|
+
result.from_step? ? rollback_organizer(result.service) : rollback_service(result.service)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Calls service own rollback.
|
36
|
+
#
|
37
|
+
# @param service [ConvenientService::Service]
|
38
|
+
# @return [void]
|
39
|
+
#
|
40
|
+
# @internal
|
41
|
+
# TODO: Compare what is faster `respond_to?` or `own_method`.
|
42
|
+
#
|
43
|
+
def rollback_service(service)
|
44
|
+
Utils::Object.safe_send(service, :rollback_result)
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Calls organizer own rollback.
|
49
|
+
# Then calls organizer steps rollbacks with nestings in the reverse order.
|
50
|
+
#
|
51
|
+
# @param organizer [ConvenientService::Service]
|
52
|
+
# @return [void]
|
53
|
+
#
|
54
|
+
def rollback_organizer(organizer)
|
55
|
+
rollback_service(organizer)
|
56
|
+
|
57
|
+
organizer.steps
|
58
|
+
.select(&:completed?)
|
59
|
+
.reject(&:method_step?)
|
60
|
+
.reverse_each { |step| rollback_result(step.service_result) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Service
|
5
|
+
module Plugins
|
6
|
+
module CanHaveSteps
|
7
|
+
module Commands
|
8
|
+
class IsStep < Support::Command
|
9
|
+
##
|
10
|
+
# @!attribute [r] step
|
11
|
+
# @return [Object] Can be any type.
|
12
|
+
#
|
13
|
+
attr_reader :step
|
14
|
+
|
15
|
+
##
|
16
|
+
# @param step [Object] Can be any type.
|
17
|
+
# @return [void]
|
18
|
+
#
|
19
|
+
def initialize(step:)
|
20
|
+
@step = step
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# @return [Boolean]
|
25
|
+
#
|
26
|
+
def call
|
27
|
+
step.class.include?(Entities::Step::Concern)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|