convenient_service 0.22.0 → 0.24.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/dependencies/queries/version.rb +18 -0
- data/lib/convenient_service/service/configs/standard.rb +7 -3
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_backtrace.rb +1 -1
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_cause.rb +1 -1
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_class.rb +1 -1
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_exception.rb +2 -2
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_line.rb +1 -1
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_message.rb +1 -1
- data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/constants.rb +1 -1
- data/lib/convenient_service/service/plugins/can_have_formatted_exceptions.rb +35 -0
- data/lib/convenient_service/service/plugins/can_have_handled_exceptions/concern.rb +34 -0
- data/lib/convenient_service/service/plugins/{has_j_send_result/entities/result/plugins/can_have_modified_data.rb → can_have_handled_exceptions.rb} +1 -2
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/commands/cast_step_aware_enumerable.rb → can_have_service_aware_enumerables/commands/cast_service_aware_enumerable.rb} +19 -19
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/commands/cast_step_aware_enumerator.rb → can_have_service_aware_enumerables/commands/cast_service_aware_enumerator.rb} +15 -15
- data/lib/convenient_service/service/plugins/can_have_service_aware_enumerables/commands.rb +9 -0
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables → can_have_service_aware_enumerables}/concern.rb +18 -9
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/arithmetic_sequence_enumerator.rb +6 -6
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/array.rb +3 -3
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/base.rb +100 -112
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/boolean.rb +3 -3
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/chain_enumerator.rb +21 -21
- data/lib/convenient_service/service/plugins/can_have_service_aware_enumerables/entities/service_aware_enumerables/enumerable.rb +1761 -0
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/enumerator.rb +49 -27
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/hash.rb +3 -3
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/lazy_enumerator/jruby.rb +40 -40
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/lazy_enumerator.rb +133 -133
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/object.rb +4 -4
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/object_or_nil.rb +3 -3
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/entities/step_aware_enumerables → can_have_service_aware_enumerables/entities/service_aware_enumerables}/set.rb +3 -3
- data/lib/convenient_service/service/plugins/can_have_service_aware_enumerables/entities/service_aware_enumerables.rb +21 -0
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables/commands.rb → can_have_service_aware_enumerables/entities.rb} +1 -2
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables → can_have_service_aware_enumerables}/exceptions.rb +2 -2
- data/lib/convenient_service/service/plugins/can_have_service_aware_enumerables.rb +12 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_used_in_service_aware_enumerables/concern.rb +52 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_used_in_service_aware_enumerables.rb +8 -0
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/middleware.rb +2 -1
- data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +1 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +4 -4
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/concern.rb +61 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception.rb +8 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_unhandled_exception/concern.rb +46 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_unhandled_exception.rb +8 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/concern.rb +97 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/entities/key_modes/base.rb +153 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/entities/key_modes/many.rb +141 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/entities/key_modes/none.rb +106 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/entities/key_modes/one.rb +146 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables/entities/key_modes.rb +54 -0
- data/lib/convenient_service/service/plugins/{can_have_step_aware_enumerables → has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables}/entities.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/{can_have_modified_data → can_be_used_in_service_aware_enumerables}/exceptions.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_used_in_service_aware_enumerables.rb +10 -0
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb +28 -10
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/exceptions.rb +1 -1
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb +3 -1
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +3 -3
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb +0 -2
- data/lib/convenient_service/service/plugins.rb +3 -1
- data/lib/convenient_service/version.rb +1 -1
- metadata +48 -34
- data/lib/convenient_service/service/plugins/can_have_step_aware_collections.rb +0 -12
- data/lib/convenient_service/service/plugins/can_have_step_aware_enumerables/entities/step_aware_enumerables/enumerable.rb +0 -1113
- data/lib/convenient_service/service/plugins/can_have_step_aware_enumerables/entities/step_aware_enumerables.rb +0 -21
- data/lib/convenient_service/service/plugins/can_have_step_aware_enumerables.rb +0 -12
- data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_modified_data/concern.rb +0 -109
- /data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b223651455eef03afc210c38e6ce570703b35bafc8543633072a019cfbb312fa
|
|
4
|
+
data.tar.gz: ace1e707494c39cfe83e4eda8b72d64b356db659ab437fe49b530b101cef23b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e79cfb96f54558b5a2382236777543b7bba3f46e3b360919ca0779359bf16a61b7784d6f5d92c6b925813a2714bb1aec20dc6a943656f85d34ba3f37de1bc23
|
|
7
|
+
data.tar.gz: 79510a4c2dc7370b01c09f82b8f062dcab488eb7113f1f85f2c5bde20af5553c1fec19f9cb69c9e81ee4a5b894a73298c793ed2a5eb125757bcb8065231c70fc
|
|
@@ -41,6 +41,24 @@ module ConvenientService
|
|
|
41
41
|
false
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
##
|
|
45
|
+
# @return [ConvenientService::Dependencies::Queries::Version]
|
|
46
|
+
#
|
|
47
|
+
# @example Beta version is considered as lower than major version.
|
|
48
|
+
# ConvenientService::Dependencies::Queries::Version.new("4.0.0.beta1") >= 4
|
|
49
|
+
# # => false
|
|
50
|
+
#
|
|
51
|
+
# @example That is why there is a way to compare only by the first segment of version.
|
|
52
|
+
# ConvenientService::Dependencies::Queries::Version.new("4.0.0.beta1").major_version >= 4
|
|
53
|
+
# # => true
|
|
54
|
+
#
|
|
55
|
+
# @internal
|
|
56
|
+
# TODO: Add direct specs.
|
|
57
|
+
#
|
|
58
|
+
def major_version
|
|
59
|
+
self.class.new(gem_version&.segments&.first.to_s)
|
|
60
|
+
end
|
|
61
|
+
|
|
44
62
|
##
|
|
45
63
|
# @return [Gem::Version, nil]
|
|
46
64
|
#
|
|
@@ -90,7 +90,7 @@ module ConvenientService
|
|
|
90
90
|
use ConvenientService::Plugins::Service::HasNegatedJSendResult::Concern if options.enabled?(:essential)
|
|
91
91
|
use ConvenientService::Plugins::Service::CanHaveSteps::Concern if options.enabled?(:essential)
|
|
92
92
|
use ConvenientService::Plugins::Service::CanHaveConnectedSteps::Concern if options.enabled?(:essential)
|
|
93
|
-
use ConvenientService::Plugins::Service::
|
|
93
|
+
use ConvenientService::Plugins::Service::CanHaveServiceAwareEnumerables::Concern if options.enabled?(:essential)
|
|
94
94
|
use ConvenientService::Plugins::Service::CanBeCalled::Concern if options.enabled?(:essential)
|
|
95
95
|
use ConvenientService::Plugins::Common::CanHaveCallbacks::Concern if options.enabled?(:callbacks)
|
|
96
96
|
use ConvenientService::Plugins::Service::CanHaveFallbacks::Concern if options.enabled?(:fallbacks)
|
|
@@ -100,6 +100,7 @@ module ConvenientService
|
|
|
100
100
|
use ConvenientService::Plugins::Common::CachesConstructorArguments::Concern if options.enabled?(:recalculation)
|
|
101
101
|
use ConvenientService::Plugins::Common::CanBeCopied::Concern if options.enabled?(:recalculation)
|
|
102
102
|
use ConvenientService::Plugins::Service::CanHaveRecalculations::Concern if options.enabled?(:recalculation)
|
|
103
|
+
use ConvenientService::Plugins::Service::CanHaveHandledExceptions::Concern if options.enabled?(:essential)
|
|
103
104
|
use ConvenientService::Plugins::Service::CanNotBeInherited::Concern if options.enabled?(:code_review_automation)
|
|
104
105
|
use ConvenientService::Plugins::Service::HasJSendResultShortSyntax::Concern if options.enabled?(:short_syntax)
|
|
105
106
|
use ConvenientService::Plugins::Service::HasJSendResultStatusCheckShortSyntax::Concern if options.enabled?(:short_syntax)
|
|
@@ -219,12 +220,14 @@ module ConvenientService
|
|
|
219
220
|
use ConvenientService::Plugins::Result::CanHaveStep::Concern if options.enabled?(:essential)
|
|
220
221
|
use ConvenientService::Plugins::Result::CanBeCalled::Concern if options.enabled?(:essential)
|
|
221
222
|
use ConvenientService::Plugins::Result::CanBeStrict::Concern if options.enabled?(:essential)
|
|
222
|
-
use ConvenientService::Plugins::Result::
|
|
223
|
+
use ConvenientService::Plugins::Result::CanBeUsedInServiceAwareEnumerables::Concern if options.enabled?(:essential)
|
|
223
224
|
use ConvenientService::Plugins::Result::HasNegatedResult::Concern if options.enabled?(:essential)
|
|
224
225
|
use ConvenientService::Plugins::Result::HasPatternMatchingSupport::Concern if options.enabled?(:essential)
|
|
225
226
|
use ConvenientService::Plugins::Result::CanBeFromFallback::Concern if options.enabled?(:fallbacks)
|
|
226
227
|
use ConvenientService::Plugins::Result::CanHaveFallbacks::Concern if options.enabled?(:fallbacks)
|
|
227
|
-
use ConvenientService::Plugins::Result::CanBeFromException::Concern if options.enabled?(:
|
|
228
|
+
use ConvenientService::Plugins::Result::CanBeFromException::Concern if options.enabled?(:essential)
|
|
229
|
+
use ConvenientService::Plugins::Result::CanBeFromHandledException::Concern if options.enabled?(:essential)
|
|
230
|
+
use ConvenientService::Plugins::Result::CanBeFromUnhandledException::Concern if options.enabled?(:fault_tolerance)
|
|
228
231
|
use ConvenientService::Plugins::Result::HasInspect::Concern if options.enabled?(:inspect)
|
|
229
232
|
use ConvenientService::Plugins::Result::HasAwesomePrintInspect::Concern if options.enabled?(:awesome_print_inspect)
|
|
230
233
|
use ConvenientService::Plugins::Result::HasAmazingPrintInspect::Concern if options.enabled?(:amazing_print_inspect)
|
|
@@ -338,6 +341,7 @@ module ConvenientService
|
|
|
338
341
|
use ConvenientService::Plugins::Step::CanBeCompleted::Concern if options.enabled?(:essential)
|
|
339
342
|
use ConvenientService::Plugins::Step::CanBeServiceStep::Concern if options.enabled?(:essential)
|
|
340
343
|
use ConvenientService::Plugins::Step::CanBeMethodStep::Concern if options.enabled?(:essential)
|
|
344
|
+
use ConvenientService::Plugins::Step::CanBeUsedInServiceAwareEnumerables::Concern if options.enabled?(:essential)
|
|
341
345
|
use ConvenientService::Plugins::Common::CanHaveCallbacks::Concern if options.enabled?(:callbacks)
|
|
342
346
|
use ConvenientService::Plugins::Step::CanHaveFallbacks::Concern if options.enabled?(:fallbacks)
|
|
343
347
|
use ConvenientService::Plugins::Step::HasInspect::Concern if options.enabled?(:inspect)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveFormattedExceptions
|
|
12
12
|
module Commands
|
|
13
13
|
class FormatException < Support::Command
|
|
14
14
|
##
|
|
@@ -49,7 +49,7 @@ module ConvenientService
|
|
|
49
49
|
# @param max_backtrace_size [Integer]
|
|
50
50
|
# @return [void]
|
|
51
51
|
#
|
|
52
|
-
def initialize(exception:, args
|
|
52
|
+
def initialize(exception:, args: [], kwargs: {}, block: nil, max_backtrace_size: Constants::DEFAULT_MAX_BACKTRACE_SIZE)
|
|
53
53
|
@exception = exception
|
|
54
54
|
@args = args
|
|
55
55
|
@kwargs = kwargs
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
require_relative "can_have_formatted_exceptions/commands"
|
|
9
|
+
require_relative "can_have_formatted_exceptions/constants"
|
|
10
|
+
|
|
11
|
+
module ConvenientService
|
|
12
|
+
module Service
|
|
13
|
+
module Plugins
|
|
14
|
+
module CanHaveFormattedExceptions
|
|
15
|
+
class << self
|
|
16
|
+
##
|
|
17
|
+
# @return [Integer]
|
|
18
|
+
#
|
|
19
|
+
def default_max_backtrace_size
|
|
20
|
+
Constants::DEFAULT_MAX_BACKTRACE_SIZE
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# @param exception [StandardError]
|
|
25
|
+
# @param kwargs [Hash{Symbol => Object}]
|
|
26
|
+
# @return [String]
|
|
27
|
+
#
|
|
28
|
+
def format_exception(exception, **kwargs)
|
|
29
|
+
Commands::FormatException.call(exception: exception, **kwargs)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
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 CanHaveHandledExceptions
|
|
12
|
+
module Concern
|
|
13
|
+
include Support::Concern
|
|
14
|
+
|
|
15
|
+
instance_methods do
|
|
16
|
+
##
|
|
17
|
+
# @api public
|
|
18
|
+
# @param max_backtrace_size [Integer]
|
|
19
|
+
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
|
|
20
|
+
#
|
|
21
|
+
def error_from_exception(exception, max_backtrace_size: Plugins::CanHaveFormattedExceptions.default_max_backtrace_size)
|
|
22
|
+
error(
|
|
23
|
+
data: {handled_exception: exception},
|
|
24
|
+
message: Plugins::CanHaveFormattedExceptions.format_exception(exception, max_backtrace_size: max_backtrace_size),
|
|
25
|
+
code: :handled_exception
|
|
26
|
+
)
|
|
27
|
+
.copy(overrides: {kwargs: {exceptions: {handled: exception}}})
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveServiceAwareEnumerables
|
|
12
12
|
module Commands
|
|
13
|
-
class
|
|
13
|
+
class CastServiceAwareEnumerable < Support::Command
|
|
14
14
|
##
|
|
15
15
|
# @return [Hash{Class => Class}]
|
|
16
16
|
#
|
|
17
|
-
|
|
18
|
-
::Array => Entities::
|
|
19
|
-
::Hash => Entities::
|
|
20
|
-
::Set => Entities::
|
|
21
|
-
::Enumerator => Entities::
|
|
22
|
-
::Enumerator::Lazy => Entities::
|
|
23
|
-
::Enumerator::Chain => Entities::
|
|
24
|
-
::Enumerator::ArithmeticSequence => Entities::
|
|
17
|
+
RUBY_CLASS_TO_SERVICE_AWARE_CLASS_MAP = {
|
|
18
|
+
::Array => Entities::ServiceAwareEnumerables::Array,
|
|
19
|
+
::Hash => Entities::ServiceAwareEnumerables::Hash,
|
|
20
|
+
::Set => Entities::ServiceAwareEnumerables::Set,
|
|
21
|
+
::Enumerator => Entities::ServiceAwareEnumerables::Enumerator,
|
|
22
|
+
::Enumerator::Lazy => Entities::ServiceAwareEnumerables::LazyEnumerator,
|
|
23
|
+
::Enumerator::Chain => Entities::ServiceAwareEnumerables::ChainEnumerator,
|
|
24
|
+
::Enumerator::ArithmeticSequence => Entities::ServiceAwareEnumerables::ArithmeticSequenceEnumerator
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
##
|
|
@@ -55,11 +55,11 @@ module ConvenientService
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
##
|
|
58
|
-
# @return [ConvenientService::Service::Plugins::
|
|
59
|
-
# @raise [ConvenientService::Service::Plugins::
|
|
58
|
+
# @return [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Entities::ServiceAwareEnumerables::Enumerable]
|
|
59
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Exceptions::ObjectIsNotEnumerable]
|
|
60
60
|
#
|
|
61
61
|
def call
|
|
62
|
-
|
|
62
|
+
service_aware_enumerable_klass&.new(**attributes) || ::ConvenientService.raise(Exceptions::ObjectIsNotEnumerable.new(object: object))
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
private
|
|
@@ -67,16 +67,16 @@ module ConvenientService
|
|
|
67
67
|
##
|
|
68
68
|
# @return [Class]
|
|
69
69
|
#
|
|
70
|
-
def
|
|
71
|
-
klass =
|
|
70
|
+
def service_aware_enumerable_klass
|
|
71
|
+
klass = RUBY_CLASS_TO_SERVICE_AWARE_CLASS_MAP[object.class]
|
|
72
72
|
|
|
73
73
|
return klass if klass
|
|
74
74
|
|
|
75
75
|
case object
|
|
76
|
-
when ::Enumerator::Lazy then Entities::
|
|
77
|
-
when ::Enumerator::Chain then Entities::
|
|
78
|
-
when ::Enumerator then Entities::
|
|
79
|
-
when ::Enumerable then Entities::
|
|
76
|
+
when ::Enumerator::Lazy then Entities::ServiceAwareEnumerables::LazyEnumerator
|
|
77
|
+
when ::Enumerator::Chain then Entities::ServiceAwareEnumerables::ChainEnumerator
|
|
78
|
+
when ::Enumerator then Entities::ServiceAwareEnumerables::Enumerator
|
|
79
|
+
when ::Enumerable then Entities::ServiceAwareEnumerables::Enumerable
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveServiceAwareEnumerables
|
|
12
12
|
module Commands
|
|
13
|
-
class
|
|
13
|
+
class CastServiceAwareEnumerator < Support::Command
|
|
14
14
|
##
|
|
15
15
|
# @return [Hash{Class => Class}]
|
|
16
16
|
#
|
|
17
|
-
|
|
18
|
-
::Enumerator => Entities::
|
|
19
|
-
::Enumerator::Lazy => Entities::
|
|
20
|
-
::Enumerator::Chain => Entities::
|
|
21
|
-
::Enumerator::ArithmeticSequence => Entities::
|
|
17
|
+
RUBY_CLASS_TO_SERVICE_AWARE_CLASS_MAP = {
|
|
18
|
+
::Enumerator => Entities::ServiceAwareEnumerables::Enumerator,
|
|
19
|
+
::Enumerator::Lazy => Entities::ServiceAwareEnumerables::LazyEnumerator,
|
|
20
|
+
::Enumerator::Chain => Entities::ServiceAwareEnumerables::ChainEnumerator,
|
|
21
|
+
::Enumerator::ArithmeticSequence => Entities::ServiceAwareEnumerables::ArithmeticSequenceEnumerator
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
##
|
|
@@ -52,11 +52,11 @@ module ConvenientService
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
##
|
|
55
|
-
# @return [ConvenientService::Service::Plugins::
|
|
56
|
-
# @raise [ConvenientService::Service::Plugins::
|
|
55
|
+
# @return [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Entities::ServiceAwareEnumerables::Enumerable]
|
|
56
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Exceptions::ObjectIsNotEnumerator]
|
|
57
57
|
#
|
|
58
58
|
def call
|
|
59
|
-
|
|
59
|
+
service_aware_enumerable_klass&.new(**attributes) || ::ConvenientService.raise(Exceptions::ObjectIsNotEnumerator.new(object: object))
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
private
|
|
@@ -64,15 +64,15 @@ module ConvenientService
|
|
|
64
64
|
##
|
|
65
65
|
# @return [Class]
|
|
66
66
|
#
|
|
67
|
-
def
|
|
68
|
-
klass =
|
|
67
|
+
def service_aware_enumerable_klass
|
|
68
|
+
klass = RUBY_CLASS_TO_SERVICE_AWARE_CLASS_MAP[object.class]
|
|
69
69
|
|
|
70
70
|
return klass if klass
|
|
71
71
|
|
|
72
72
|
case object
|
|
73
|
-
when ::Enumerator::Lazy then Entities::
|
|
74
|
-
when ::Enumerator::Chain then Entities::
|
|
75
|
-
when ::Enumerator then Entities::
|
|
73
|
+
when ::Enumerator::Lazy then Entities::ServiceAwareEnumerables::LazyEnumerator
|
|
74
|
+
when ::Enumerator::Chain then Entities::ServiceAwareEnumerables::ChainEnumerator
|
|
75
|
+
when ::Enumerator then Entities::ServiceAwareEnumerables::Enumerator
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
require_relative "commands/cast_service_aware_enumerable"
|
|
9
|
+
require_relative "commands/cast_service_aware_enumerator"
|
|
@@ -8,31 +8,40 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveServiceAwareEnumerables
|
|
12
12
|
module Concern
|
|
13
13
|
include Support::Concern
|
|
14
14
|
|
|
15
|
+
##
|
|
16
|
+
# TODO: Implement in `CanBeUsedInServiceAwareEnumerables`.
|
|
17
|
+
#
|
|
18
|
+
# class_methods do
|
|
19
|
+
# def to_service_aware_iteration_block_value
|
|
20
|
+
# end
|
|
21
|
+
# end
|
|
22
|
+
##
|
|
23
|
+
|
|
15
24
|
instance_methods do
|
|
16
25
|
##
|
|
17
26
|
# @api public
|
|
18
27
|
#
|
|
19
28
|
# @param object [Object] Can be any type.
|
|
20
|
-
# @return [ConvenientService::Service::Plugins::
|
|
21
|
-
# @raise [ConvenientService::Service::Plugins::
|
|
29
|
+
# @return [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Entities::ServiceAwareEnumerables::Enumerable]
|
|
30
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Exceptions::ObjectIsNotEnumerable]
|
|
22
31
|
#
|
|
23
|
-
def
|
|
24
|
-
Commands::
|
|
32
|
+
def service_aware_enumerable(object)
|
|
33
|
+
Commands::CastServiceAwareEnumerable.call(object: object, organizer: self)
|
|
25
34
|
end
|
|
26
35
|
|
|
27
36
|
##
|
|
28
37
|
# @api public
|
|
29
38
|
#
|
|
30
39
|
# @param object [Object] Can be any type.
|
|
31
|
-
# @return [ConvenientService::Service::Plugins::
|
|
32
|
-
# @raise [ConvenientService::Service::Plugins::
|
|
40
|
+
# @return [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Entities::ServiceAwareEnumerables::Enumerator]
|
|
41
|
+
# @raise [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Exceptions::ObjectIsNotEnumerator]
|
|
33
42
|
#
|
|
34
|
-
def
|
|
35
|
-
Commands::
|
|
43
|
+
def service_aware_enumerator(object)
|
|
44
|
+
Commands::CastServiceAwareEnumerator.call(object: object, organizer: self)
|
|
36
45
|
end
|
|
37
46
|
end
|
|
38
47
|
end
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveServiceAwareEnumerables
|
|
12
12
|
module Entities
|
|
13
|
-
module
|
|
14
|
-
class ArithmeticSequenceEnumerator < Entities::
|
|
13
|
+
module ServiceAwareEnumerables
|
|
14
|
+
class ArithmeticSequenceEnumerator < Entities::ServiceAwareEnumerables::Enumerator
|
|
15
15
|
##
|
|
16
16
|
# @api private
|
|
17
17
|
#
|
|
@@ -39,11 +39,11 @@ module ConvenientService
|
|
|
39
39
|
|
|
40
40
|
##
|
|
41
41
|
# @param iteration_block [Proc, nil]
|
|
42
|
-
# @return [ConvenientService::Service::Plugins::
|
|
42
|
+
# @return [ConvenientService::Service::Plugins::CanHaveServiceAwareEnumerables::Entities::ServiceAwareEnumerables::Enumerable]
|
|
43
43
|
#
|
|
44
44
|
def each(&iteration_block)
|
|
45
|
-
with_processing_return_value_as_arithmetic_sequence_enumerator(arguments(&iteration_block)) do |&
|
|
46
|
-
enumerable.each(&
|
|
45
|
+
with_processing_return_value_as_arithmetic_sequence_enumerator(arguments(&iteration_block)) do |&service_aware_iteration_block|
|
|
46
|
+
enumerable.each(&service_aware_iteration_block)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
module ConvenientService
|
|
9
9
|
module Service
|
|
10
10
|
module Plugins
|
|
11
|
-
module
|
|
11
|
+
module CanHaveServiceAwareEnumerables
|
|
12
12
|
module Entities
|
|
13
|
-
module
|
|
14
|
-
class Array < Entities::
|
|
13
|
+
module ServiceAwareEnumerables
|
|
14
|
+
class Array < Entities::ServiceAwareEnumerables::Enumerable
|
|
15
15
|
##
|
|
16
16
|
# @api private
|
|
17
17
|
#
|