convenient_service 0.24.0 → 0.26.0
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.
- checksums.yaml +4 -4
- data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result/middleware.rb +54 -0
- data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result.rb +8 -0
- data/lib/convenient_service/common/plugins.rb +1 -0
- data/lib/convenient_service/dependencies/queries.rb +4 -2
- data/lib/convenient_service/extras/rspec.rb +1 -1
- data/lib/convenient_service/logger.rb +6 -3
- data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/error/commands/generate_got_jsend_attributes_part.rb +1 -1
- data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/failure/commands/generate_got_jsend_attributes_part.rb +1 -1
- data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/success/commands/generate_got_jsend_attributes_part.rb +1 -1
- data/lib/convenient_service/rspec/matchers/classes/results/be_error.rb +1 -1
- data/lib/convenient_service/rspec/matchers/classes/results/be_failure.rb +1 -1
- data/lib/convenient_service/rspec/matchers/classes/results/be_not_error.rb +2 -2
- data/lib/convenient_service/rspec/matchers/classes/results/be_not_failure.rb +2 -2
- data/lib/convenient_service/rspec/matchers/classes/results/be_not_success.rb +2 -2
- data/lib/convenient_service/rspec/matchers/classes/results/be_success.rb +1 -1
- data/lib/convenient_service/service/configs/standard.rb +17 -5
- data/lib/convenient_service/service/plugins/can_have_after_step_callbacks/middleware.rb +5 -1
- data/lib/convenient_service/service/plugins/can_have_around_step_callbacks/middleware.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_before_step_callbacks/middleware.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_connected_steps/concern.rb +1 -6
- data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/scalar.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_inline_services/concern.rb +29 -0
- data/lib/convenient_service/service/plugins/can_have_inline_services/entities/proxy.rb +205 -0
- data/lib/convenient_service/service/plugins/{can_have_steps/entities/step/plugins/can_be_completed.rb → can_have_inline_services/entities.rb} +1 -1
- data/lib/convenient_service/service/plugins/can_have_inline_services/exceptions.rb +30 -0
- data/lib/convenient_service/service/plugins/can_have_inline_services.rb +36 -0
- data/lib/convenient_service/service/plugins/can_have_sequential_steps/concern.rb +2 -0
- data/lib/convenient_service/service/plugins/can_have_sequential_steps/middleware.rb +1 -5
- data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +1 -6
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +5 -8
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/proc.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/raw.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/key.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +13 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/{can_be_completed → can_be_evaluated}/concern.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_evaluated.rb +8 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/concern.rb +37 -12
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/exceptions.rb +38 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception.rb +1 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb +7 -0
- data/lib/convenient_service/service/plugins/has_j_send_result.rb +84 -0
- data/lib/convenient_service/service/plugins/raises_on_not_result_return_value/middleware.rb +7 -3
- data/lib/convenient_service/service/plugins.rb +1 -0
- data/lib/convenient_service/version.rb +1 -1
- data/lib/convenient_service.rb +23 -1
- metadata +12 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31bdaa61be77d7c69da22c3baaf05b545d60606fbf45e9a7baac33929e845544
|
|
4
|
+
data.tar.gz: 7fa4432c8ce4b57a43b3bbcc9c8ea18d5002b69fc00db81da0cba78c9ac8ba54
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8195321c43354288cd9d99a74a3384dbc552ca4845d0fa58ef347a34e21cab420c284a4bed10ea62d71885c02cff5e3999b9956facd50d8ea58928eb74e7cf67
|
|
7
|
+
data.tar.gz: 9d4007218ddf5eb3061a57f6038af8596c7e98bf8dc4791acf7e0ef66e1a0b9987d36689e508747eeef54c3fa7f4291374a500b032a5944e03c677a26feb0110
|
data/lib/convenient_service/common/plugins/tries_to_convert_result_duck_to_result/middleware.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Common
|
|
10
|
+
module Plugins
|
|
11
|
+
module TriesToConvertResultDuckToResult
|
|
12
|
+
class Middleware < MethodChainMiddleware
|
|
13
|
+
intended_for :result, entity: any_entity
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
|
17
|
+
#
|
|
18
|
+
# @internal
|
|
19
|
+
# NOTE: When original result is a result duck and it has `NoMethodError` exception, that exception should be raised just like any other exception. See specs for details.
|
|
20
|
+
#
|
|
21
|
+
# NOTE: `exception.receiver` is available on `NameError` descendants (like `NoMethodError`), but NOT on `StandardError`.
|
|
22
|
+
# - https://ruby-doc.org/core-2.7.1/NoMethodError.html
|
|
23
|
+
# - https://ruby-doc.org/core-2.7.1/NameError.html#method-i-receiver
|
|
24
|
+
# - https://ruby-doc.org/core-2.7.1/StandardError.html
|
|
25
|
+
#
|
|
26
|
+
def next(...)
|
|
27
|
+
original_object = chain.next(...)
|
|
28
|
+
|
|
29
|
+
result_duck, result = try_convert(original_object)
|
|
30
|
+
|
|
31
|
+
result_duck ? result : original_object
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# @param original_object [Object] Can be any type.
|
|
38
|
+
# @return [Array]
|
|
39
|
+
# @raise [NoMethodError]
|
|
40
|
+
#
|
|
41
|
+
def try_convert(original_object)
|
|
42
|
+
result = original_object.result
|
|
43
|
+
|
|
44
|
+
[true, result]
|
|
45
|
+
rescue ::NoMethodError => exception
|
|
46
|
+
raise exception if original_object.respond_to?(:result)
|
|
47
|
+
|
|
48
|
+
[false, nil]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -14,6 +14,7 @@ require_relative "plugins/caches_return_value"
|
|
|
14
14
|
require_relative "plugins/can_be_copied"
|
|
15
15
|
require_relative "plugins/can_have_user_provided_entity"
|
|
16
16
|
require_relative "plugins/ensures_negated_j_send_result"
|
|
17
|
+
require_relative "plugins/tries_to_convert_result_duck_to_result"
|
|
17
18
|
require_relative "plugins/can_have_callbacks"
|
|
18
19
|
require_relative "plugins/can_have_not_passed_arguments"
|
|
19
20
|
require_relative "plugins/can_utilize_finite_loop"
|
|
@@ -25,10 +25,12 @@ module ConvenientService
|
|
|
25
25
|
##
|
|
26
26
|
# Returns `true` when Convenient Service is in debug mode. In other words `$CONVENIENT_SERVICE_DEBUG` env variable is set to `true`.
|
|
27
27
|
#
|
|
28
|
-
# @api
|
|
28
|
+
# @api public
|
|
29
29
|
# @since 1.0.0
|
|
30
30
|
# @return [Boolean]
|
|
31
31
|
#
|
|
32
|
+
# @see https://userdocs.convenientservice.org/comprehensive_docs/docs/the_how/how_to_debug_the_convenient_service_lib_itself.html
|
|
33
|
+
#
|
|
32
34
|
def debug?
|
|
33
35
|
::ENV["CONVENIENT_SERVICE_DEBUG"] == "true"
|
|
34
36
|
end
|
|
@@ -499,7 +501,7 @@ module ConvenientService
|
|
|
499
501
|
# @return [Boolean]
|
|
500
502
|
# @note Expected to be called from `spec_helper.rb`.
|
|
501
503
|
#
|
|
502
|
-
def
|
|
504
|
+
def require_rspec_extensions
|
|
503
505
|
require "rspec/expectations"
|
|
504
506
|
require "rspec/matchers"
|
|
505
507
|
require "rspec/mocks"
|
|
@@ -46,10 +46,10 @@ module ConvenientService
|
|
|
46
46
|
def new
|
|
47
47
|
super(::STDOUT).tap do |logger|
|
|
48
48
|
logger.level =
|
|
49
|
-
if ::ENV["
|
|
50
|
-
::Logger::DEBUG
|
|
51
|
-
elsif ::ENV["CONVENIENT_SERVICE_LOGGER_LEVEL"]
|
|
49
|
+
if ::ENV["CONVENIENT_SERVICE_LOGGER_LEVEL"]
|
|
52
50
|
::ENV["CONVENIENT_SERVICE_LOGGER_LEVEL"]
|
|
51
|
+
elsif ::ENV["CONVENIENT_SERVICE_DEBUG"] == "true"
|
|
52
|
+
::Logger::DEBUG
|
|
53
53
|
else
|
|
54
54
|
::Logger::INFO
|
|
55
55
|
end
|
|
@@ -98,6 +98,9 @@ module ConvenientService
|
|
|
98
98
|
##
|
|
99
99
|
# @api public
|
|
100
100
|
#
|
|
101
|
+
# @see https://userdocs.convenientservice.org/comprehensive_docs/docs/the_what/what_is_convenient_service_logger.html
|
|
102
|
+
# @see https://userdocs.convenientservice.org/comprehensive_docs/docs/the_how/how_to_configure_convenient_service_logger.html
|
|
103
|
+
#
|
|
101
104
|
# @internal
|
|
102
105
|
# IMPORTANT: Older versions of `Logger` do NOT support `level` as a string.
|
|
103
106
|
# - https://github.com/ruby/logger/blob/v1.2.8.1/lib/logger.rb#L333
|
|
@@ -90,7 +90,7 @@ module ConvenientService
|
|
|
90
90
|
# @return [String]
|
|
91
91
|
#
|
|
92
92
|
def code_part
|
|
93
|
-
(code == Service::Plugins::HasJSendResult
|
|
93
|
+
(code == Service::Plugins::HasJSendResult.default_error_code) ? "" : "with code `#{code}`"
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
##
|
|
@@ -90,7 +90,7 @@ module ConvenientService
|
|
|
90
90
|
# @return [String]
|
|
91
91
|
#
|
|
92
92
|
def code_part
|
|
93
|
-
(code == Service::Plugins::HasJSendResult
|
|
93
|
+
(code == Service::Plugins::HasJSendResult.default_failure_code) ? "" : "with code `#{code}`"
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
##
|
|
@@ -90,7 +90,7 @@ module ConvenientService
|
|
|
90
90
|
# @return [String]
|
|
91
91
|
#
|
|
92
92
|
def code_part
|
|
93
|
-
(code == Service::Plugins::HasJSendResult
|
|
93
|
+
(code == Service::Plugins::HasJSendResult.default_success_code) ? "" : "with code `#{code}`"
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
##
|
|
@@ -18,8 +18,8 @@ module ConvenientService
|
|
|
18
18
|
#
|
|
19
19
|
def statuses
|
|
20
20
|
[
|
|
21
|
-
Service::Plugins::HasJSendResult
|
|
22
|
-
Service::Plugins::HasJSendResult
|
|
21
|
+
Service::Plugins::HasJSendResult.success_status,
|
|
22
|
+
Service::Plugins::HasJSendResult.failure_status
|
|
23
23
|
]
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -18,8 +18,8 @@ module ConvenientService
|
|
|
18
18
|
#
|
|
19
19
|
def statuses
|
|
20
20
|
[
|
|
21
|
-
Service::Plugins::HasJSendResult
|
|
22
|
-
Service::Plugins::HasJSendResult
|
|
21
|
+
Service::Plugins::HasJSendResult.success_status,
|
|
22
|
+
Service::Plugins::HasJSendResult.error_status
|
|
23
23
|
]
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -18,8 +18,8 @@ module ConvenientService
|
|
|
18
18
|
#
|
|
19
19
|
def statuses
|
|
20
20
|
[
|
|
21
|
-
Service::Plugins::HasJSendResult
|
|
22
|
-
Service::Plugins::HasJSendResult
|
|
21
|
+
Service::Plugins::HasJSendResult.failure_status,
|
|
22
|
+
Service::Plugins::HasJSendResult.error_status
|
|
23
23
|
]
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -29,6 +29,7 @@ module ConvenientService
|
|
|
29
29
|
:result_parents_trace,
|
|
30
30
|
:code_review_automation,
|
|
31
31
|
:short_syntax,
|
|
32
|
+
:duck_typing,
|
|
32
33
|
:type_safety,
|
|
33
34
|
:exception_services_trace,
|
|
34
35
|
:per_instance_caching,
|
|
@@ -58,6 +59,7 @@ module ConvenientService
|
|
|
58
59
|
:result_parents_trace,
|
|
59
60
|
:code_review_automation,
|
|
60
61
|
:short_syntax,
|
|
62
|
+
:duck_typing,
|
|
61
63
|
:type_safety,
|
|
62
64
|
:exception_services_trace,
|
|
63
65
|
:per_instance_caching,
|
|
@@ -94,6 +96,7 @@ module ConvenientService
|
|
|
94
96
|
use ConvenientService::Plugins::Service::CanBeCalled::Concern if options.enabled?(:essential)
|
|
95
97
|
use ConvenientService::Plugins::Common::CanHaveCallbacks::Concern if options.enabled?(:callbacks)
|
|
96
98
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Concern if options.enabled?(:fallbacks)
|
|
99
|
+
use ConvenientService::Plugins::Service::CanHaveInlineServices::Concern if options.enabled?(:essential)
|
|
97
100
|
use ConvenientService::Plugins::Service::HasInspect::Concern if options.enabled?(:inspect)
|
|
98
101
|
use ConvenientService::Plugins::Service::HasAwesomePrintInspect::Concern if options.enabled?(:awesome_print_inspect)
|
|
99
102
|
use ConvenientService::Plugins::Service::HasAmazingPrintInspect::Concern if options.enabled?(:amazing_print_inspect)
|
|
@@ -133,6 +136,7 @@ module ConvenientService
|
|
|
133
136
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware if options.enabled?(:type_safety)
|
|
134
137
|
use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance)
|
|
135
138
|
use ConvenientService::Plugins::Common::CleansExceptionBacktrace::Middleware if options.enabled?(:backtrace_cleaner)
|
|
139
|
+
use ConvenientService::Plugins::Common::TriesToConvertResultDuckToResult::Middleware if options.enabled?(:duck_typing)
|
|
136
140
|
use ConvenientService::Plugins::Service::HasJSendResultParamsValidations::UsingActiveModelValidations::Middleware if options.enabled?(:active_model_validations)
|
|
137
141
|
use ConvenientService::Plugins::Service::HasJSendResultParamsValidations::UsingDryValidation::Middleware if options.enabled?(:dry_validation)
|
|
138
142
|
use ConvenientService::Plugins::Service::CanHaveConnectedSteps::Middleware if options.enabled?(:essential)
|
|
@@ -145,6 +149,7 @@ module ConvenientService
|
|
|
145
149
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware if options.enabled?(:type_safety)
|
|
146
150
|
use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance)
|
|
147
151
|
use ConvenientService::Plugins::Common::CleansExceptionBacktrace::Middleware if options.enabled?(:backtrace_cleaner)
|
|
152
|
+
use ConvenientService::Plugins::Common::TriesToConvertResultDuckToResult::Middleware if options.enabled?(:duck_typing)
|
|
148
153
|
end
|
|
149
154
|
|
|
150
155
|
middlewares :regular_result do
|
|
@@ -159,27 +164,30 @@ module ConvenientService
|
|
|
159
164
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
160
165
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware if options.enabled?(:exception_services_trace)
|
|
161
166
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware if options.enabled?(:type_safety)
|
|
162
|
-
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO:
|
|
167
|
+
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO: Dedicated `rescue`?
|
|
163
168
|
use ConvenientService::Plugins::Common::CleansExceptionBacktrace::Middleware if options.enabled?(:backtrace_cleaner)
|
|
164
169
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: :failure) if options.enabled?(:fallbacks)
|
|
170
|
+
use ConvenientService::Plugins::Common::TriesToConvertResultDuckToResult::Middleware if options.enabled?(:duck_typing)
|
|
165
171
|
end
|
|
166
172
|
|
|
167
173
|
middlewares :fallback_error_result do
|
|
168
174
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
169
175
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware if options.enabled?(:exception_services_trace)
|
|
170
176
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware if options.enabled?(:type_safety)
|
|
171
|
-
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO:
|
|
177
|
+
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO: Dedicated `rescue`?
|
|
172
178
|
use ConvenientService::Plugins::Common::CleansExceptionBacktrace::Middleware if options.enabled?(:backtrace_cleaner)
|
|
173
179
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: :error) if options.enabled?(:fallbacks)
|
|
180
|
+
use ConvenientService::Plugins::Common::TriesToConvertResultDuckToResult::Middleware if options.enabled?(:duck_typing)
|
|
174
181
|
end
|
|
175
182
|
|
|
176
183
|
middlewares :fallback_result do
|
|
177
184
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
178
185
|
use ConvenientService::Plugins::Service::CollectsServicesInException::Middleware if options.enabled?(:exception_services_trace)
|
|
179
186
|
use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware if options.enabled?(:type_safety)
|
|
180
|
-
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO:
|
|
187
|
+
# use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware if options.enabled?(:fault_tolerance) # TODO: Dedicated `rescue`?
|
|
181
188
|
use ConvenientService::Plugins::Common::CleansExceptionBacktrace::Middleware if options.enabled?(:backtrace_cleaner)
|
|
182
189
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Middleware.with(status: nil) if options.enabled?(:fallbacks)
|
|
190
|
+
use ConvenientService::Plugins::Common::TriesToConvertResultDuckToResult::Middleware if options.enabled?(:duck_typing)
|
|
183
191
|
end
|
|
184
192
|
|
|
185
193
|
middlewares :success do
|
|
@@ -338,7 +346,7 @@ module ConvenientService
|
|
|
338
346
|
concerns do
|
|
339
347
|
use ConvenientService::Plugins::Common::HasInternals::Concern if options.enabled?(:essential)
|
|
340
348
|
use ConvenientService::Plugins::Step::HasResult::Concern if options.enabled?(:essential)
|
|
341
|
-
use ConvenientService::Plugins::Step::
|
|
349
|
+
use ConvenientService::Plugins::Step::CanBeEvaluated::Concern if options.enabled?(:essential)
|
|
342
350
|
use ConvenientService::Plugins::Step::CanBeServiceStep::Concern if options.enabled?(:essential)
|
|
343
351
|
use ConvenientService::Plugins::Step::CanBeMethodStep::Concern if options.enabled?(:essential)
|
|
344
352
|
use ConvenientService::Plugins::Step::CanBeUsedInServiceAwareEnumerables::Concern if options.enabled?(:essential)
|
|
@@ -352,7 +360,6 @@ module ConvenientService
|
|
|
352
360
|
|
|
353
361
|
middlewares :result do
|
|
354
362
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
355
|
-
use ConvenientService::Plugins::Common::CanHaveCallbacks::Middleware if options.enabled?(:callbacks)
|
|
356
363
|
use ConvenientService::Plugins::Step::HasResult::Middleware if options.enabled?(:essential)
|
|
357
364
|
use ConvenientService::Plugins::Step::CanHaveParentResult::Middleware if options.enabled?(:result_parents_trace)
|
|
358
365
|
use ConvenientService::Plugins::Step::CanHaveFallbacks::Middleware.with(fallback_true_status: :failure) if options.enabled?(:fallbacks)
|
|
@@ -369,6 +376,11 @@ module ConvenientService
|
|
|
369
376
|
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
370
377
|
end
|
|
371
378
|
|
|
379
|
+
middlewares :organizer_result do
|
|
380
|
+
use ConvenientService::Plugins::Common::CachesReturnValue::Middleware if options.enabled?(:per_instance_caching)
|
|
381
|
+
use ConvenientService::Plugins::Common::CanHaveCallbacks::Middleware if options.enabled?(:callbacks)
|
|
382
|
+
end
|
|
383
|
+
|
|
372
384
|
entity :Internals do
|
|
373
385
|
concerns do
|
|
374
386
|
use ConvenientService::Plugins::Internals::HasCache::Concern if options.enabled?(:per_instance_caching)
|
|
@@ -65,11 +65,15 @@ module ConvenientService
|
|
|
65
65
|
# end
|
|
66
66
|
# end
|
|
67
67
|
#
|
|
68
|
+
# @internal
|
|
69
|
+
# IMPORTANT: `result.step.result` does NOT take result from internal cache, it raises instead. That is frustrating to the end-users, but there is NO workaroud yet.
|
|
70
|
+
# TODO: Think about passing `result` with `callback_arguments`. Not perfect, but better than nothing.
|
|
71
|
+
#
|
|
68
72
|
def next(method, **kwargs, &block)
|
|
69
73
|
return chain.next(method, **kwargs, &block) if method != :step
|
|
70
74
|
|
|
71
75
|
entity.step_class.class_exec(kwargs, block) do |kwargs, block|
|
|
72
|
-
after :
|
|
76
|
+
after :organizer_result, **kwargs.merge(source_location: block.source_location) do |result|
|
|
73
77
|
organizer.instance_exec(
|
|
74
78
|
result.step,
|
|
75
79
|
params.to_callback_arguments,
|
|
@@ -73,7 +73,7 @@ module ConvenientService
|
|
|
73
73
|
return chain.next(method, **kwargs, &block) if method != :step
|
|
74
74
|
|
|
75
75
|
entity.step_class.class_exec(kwargs, block) do |kwargs, block|
|
|
76
|
-
around :
|
|
76
|
+
around :organizer_result, **kwargs.merge(source_location: block.source_location) do |chain|
|
|
77
77
|
organizer.instance_exec(
|
|
78
78
|
proc { chain.yield.step },
|
|
79
79
|
params.to_callback_arguments,
|
|
@@ -69,7 +69,7 @@ module ConvenientService
|
|
|
69
69
|
return chain.next(method, **kwargs, &block) if method != :step
|
|
70
70
|
|
|
71
71
|
entity.step_class.class_exec(kwargs, block) do |kwargs, block|
|
|
72
|
-
before :
|
|
72
|
+
before :organizer_result, **kwargs.merge(source_location: block.source_location) do
|
|
73
73
|
organizer.instance_exec(
|
|
74
74
|
params.to_callback_arguments,
|
|
75
75
|
&block
|
|
@@ -23,6 +23,7 @@ module ConvenientService
|
|
|
23
23
|
# @return [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base]
|
|
24
24
|
#
|
|
25
25
|
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
|
|
26
|
+
# @see https://userdocs.convenientservice.org/comprehensive_docs/docs/the_what/what_step_input_types_are_available.html
|
|
26
27
|
#
|
|
27
28
|
def step(*args, **kwargs)
|
|
28
29
|
previous_expression = steps.expression
|
|
@@ -717,12 +718,6 @@ module ConvenientService
|
|
|
717
718
|
def steps_result
|
|
718
719
|
::ConvenientService.raise Exceptions::ServiceHasNoSteps.new(service_class: self.class) if steps.none?
|
|
719
720
|
|
|
720
|
-
steps.each_evaluated_step do |step|
|
|
721
|
-
step.save_outputs_in_organizer!
|
|
722
|
-
|
|
723
|
-
step.mark_as_evaluated!
|
|
724
|
-
end
|
|
725
|
-
|
|
726
721
|
steps.result
|
|
727
722
|
end
|
|
728
723
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveInlineServices
|
|
12
|
+
module Concern
|
|
13
|
+
include Support::Concern
|
|
14
|
+
|
|
15
|
+
instance_methods do
|
|
16
|
+
##
|
|
17
|
+
# @api private
|
|
18
|
+
# @param block [Proc, nil]
|
|
19
|
+
# @return [ConvenientService::Service::Plugins::CanHaveInlineServices::Entities::Proxy]
|
|
20
|
+
#
|
|
21
|
+
def inline(&block)
|
|
22
|
+
Entities::Proxy.new(&block)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# @author Marian Kostyk <mariankostyk13895@gmail.com>
|
|
5
|
+
# @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
module ConvenientService
|
|
9
|
+
module Service
|
|
10
|
+
module Plugins
|
|
11
|
+
module CanHaveInlineServices
|
|
12
|
+
module Entities
|
|
13
|
+
##
|
|
14
|
+
# @internal
|
|
15
|
+
# TODO: Specs.
|
|
16
|
+
#
|
|
17
|
+
class Proxy
|
|
18
|
+
##
|
|
19
|
+
# @param chain [Hash{Symbol => Object}]
|
|
20
|
+
# @param block [Proc, nil]
|
|
21
|
+
# @return [void]
|
|
22
|
+
#
|
|
23
|
+
def initialize(chain: {}, &block)
|
|
24
|
+
@chain = chain
|
|
25
|
+
|
|
26
|
+
if block
|
|
27
|
+
chain[:block] = block
|
|
28
|
+
|
|
29
|
+
define
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# @return [Boolean]
|
|
35
|
+
#
|
|
36
|
+
def defined?
|
|
37
|
+
chain.has_key?(:defined)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# @return [Boolean]
|
|
42
|
+
#
|
|
43
|
+
def define
|
|
44
|
+
return false if self.defined?
|
|
45
|
+
|
|
46
|
+
klass.include config
|
|
47
|
+
|
|
48
|
+
variables.each_pair { |key, value| klass.define_method(key) { value } }
|
|
49
|
+
|
|
50
|
+
klass.class_exec(arguments, &block)
|
|
51
|
+
|
|
52
|
+
mark_as_defined!
|
|
53
|
+
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# @return [ConvenientService::Service::Plugins::CanHaveInlineServices::Entities::Proxy]
|
|
59
|
+
#
|
|
60
|
+
def with_arguments(...)
|
|
61
|
+
assert_not_defined!
|
|
62
|
+
|
|
63
|
+
chain[:arguments] = Support::Arguments.new(...)
|
|
64
|
+
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# @param variables [Hash{Symbol => Object}]
|
|
70
|
+
# @return [ConvenientService::Service::Plugins::CanHaveInlineServices::Entities::Proxy]
|
|
71
|
+
#
|
|
72
|
+
def with_variables(**variables)
|
|
73
|
+
assert_not_defined!
|
|
74
|
+
|
|
75
|
+
chain[:variables] = variables
|
|
76
|
+
|
|
77
|
+
self
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# @param config [ConvenientService::Config]
|
|
82
|
+
# @return [ConvenientService::Service::Plugins::CanHaveInlineServices::Entities::Proxy]
|
|
83
|
+
#
|
|
84
|
+
def with_config(config)
|
|
85
|
+
assert_not_defined!
|
|
86
|
+
|
|
87
|
+
chain[:config] = config
|
|
88
|
+
|
|
89
|
+
self
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# @param block [Proc, nil]
|
|
94
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
|
95
|
+
#
|
|
96
|
+
def result(&block)
|
|
97
|
+
if block
|
|
98
|
+
assert_not_defined!
|
|
99
|
+
|
|
100
|
+
chain[:block] = block
|
|
101
|
+
|
|
102
|
+
define
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
klass.result
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
##
|
|
109
|
+
# @param block [Proc, nil]
|
|
110
|
+
# @return [Class<ConvenientService::Service>]
|
|
111
|
+
#
|
|
112
|
+
def to_class(&block)
|
|
113
|
+
if block
|
|
114
|
+
assert_not_defined!
|
|
115
|
+
|
|
116
|
+
chain[:block] = block
|
|
117
|
+
|
|
118
|
+
define
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
klass
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
##
|
|
125
|
+
# @return [Class<ConvenientService::Service>]
|
|
126
|
+
#
|
|
127
|
+
alias_method :service, :to_class
|
|
128
|
+
|
|
129
|
+
##
|
|
130
|
+
# @param other [Object] Can be any type.
|
|
131
|
+
# @return [Boolean, nil]
|
|
132
|
+
#
|
|
133
|
+
def ==(other)
|
|
134
|
+
return unless other.instance_of?(self.class)
|
|
135
|
+
|
|
136
|
+
return false if chain != other.chain
|
|
137
|
+
|
|
138
|
+
true
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
protected
|
|
142
|
+
|
|
143
|
+
##
|
|
144
|
+
# @!attribute [r] value
|
|
145
|
+
# @return [Hash{Symbol => Object}]
|
|
146
|
+
#
|
|
147
|
+
attr_reader :chain
|
|
148
|
+
|
|
149
|
+
private
|
|
150
|
+
|
|
151
|
+
##
|
|
152
|
+
# @return [Class]
|
|
153
|
+
#
|
|
154
|
+
def klass
|
|
155
|
+
@klass ||= ::Class.new
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
##
|
|
159
|
+
# @return [ConvenientService::Support::Arguments]
|
|
160
|
+
#
|
|
161
|
+
def arguments
|
|
162
|
+
chain[:arguments] || Support::Arguments.null_arguments
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
##
|
|
166
|
+
# @return [Hash{Symbol => Object}]
|
|
167
|
+
#
|
|
168
|
+
def variables
|
|
169
|
+
chain[:variables] || {}
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# @return [ConvenientService::Config]
|
|
174
|
+
#
|
|
175
|
+
def config
|
|
176
|
+
chain[:config] || ::ConvenientService::Standard::Config
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
##
|
|
180
|
+
# @return [Proc]
|
|
181
|
+
#
|
|
182
|
+
def block
|
|
183
|
+
chain[:block] || proc {}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
##
|
|
187
|
+
# @return [void]
|
|
188
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveInlineServices::Exceptions::InlineServiceIsAlreadyDefined]
|
|
189
|
+
#
|
|
190
|
+
def assert_not_defined!
|
|
191
|
+
::ConvenientService.raise Exceptions::InlineServiceIsAlreadyDefined if self.defined?
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
##
|
|
195
|
+
# @return [void]
|
|
196
|
+
#
|
|
197
|
+
def mark_as_defined!
|
|
198
|
+
chain[:defined] = true
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|