convenient_service 0.20.0 → 0.21.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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/lib/convenient_service/aliases.rb +113 -1
  4. data/lib/convenient_service/common/plugins/aliases.rb +69 -0
  5. data/lib/convenient_service/common/plugins/can_have_callbacks/entities/type_collection.rb +2 -2
  6. data/lib/convenient_service/common/plugins/has_instance_proxy/entities/instance_proxy.rb +8 -8
  7. data/lib/convenient_service/common.rb +14 -0
  8. data/lib/convenient_service/config.rb +8 -0
  9. data/lib/convenient_service/core/aliases.rb +84 -0
  10. data/lib/convenient_service/dependencies/built_in.rb +15 -1
  11. data/lib/convenient_service/dependencies/only_queries.rb +0 -6
  12. data/lib/convenient_service/dependencies/queries/gems/minitest.rb +55 -0
  13. data/lib/convenient_service/dependencies/queries/gems/rspec.rb +1 -1
  14. data/lib/convenient_service/dependencies/queries/gems.rb +2 -0
  15. data/lib/convenient_service/dependencies/queries/ruby.rb +2 -2
  16. data/lib/convenient_service/dependencies/queries.rb +67 -16
  17. data/lib/convenient_service/dependencies.rb +6 -6
  18. data/lib/convenient_service/extras/alias.rb +4 -1
  19. data/lib/convenient_service/feature/configs/standard.rb +34 -13
  20. data/lib/convenient_service/feature/core.rb +41 -0
  21. data/lib/convenient_service/feature/plugins/aliases.rb +29 -0
  22. data/lib/convenient_service/feature/plugins/can_have_rspec_stubbed_entries/concern.rb +34 -0
  23. data/lib/convenient_service/{rspec/helpers/classes/stub_entry/entities.rb → feature/plugins/can_have_rspec_stubbed_entries.rb} +1 -2
  24. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/delete_feature_stubbed_entry.rb +71 -0
  25. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_all_features_stubbed_entries_cache.rb +16 -2
  26. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands/fetch_feature_stubbed_entries_cache.rb +1 -1
  27. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/commands.rb +2 -0
  28. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/concern.rb +23 -0
  29. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_stub.rb +123 -0
  30. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/feature_unstub.rb +122 -0
  31. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_mock.rb +118 -0
  32. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities/value_unmock.rb +88 -0
  33. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries/entities.rb +12 -0
  34. data/lib/convenient_service/feature/plugins/can_have_stubbed_entries.rb +1 -14
  35. data/lib/convenient_service/feature/plugins/has_amazing_print_inspect/concern.rb +34 -0
  36. data/lib/convenient_service/feature/{configs/standard/commands.rb → plugins/has_amazing_print_inspect.rb} +1 -2
  37. data/lib/convenient_service/feature/plugins/has_awesome_print_inspect/concern.rb +34 -0
  38. data/lib/convenient_service/{rspec/helpers/classes/stub_service/entities.rb → feature/plugins/has_awesome_print_inspect.rb} +1 -2
  39. data/lib/convenient_service/feature/plugins/has_inspect/concern.rb +27 -0
  40. data/lib/convenient_service/{service/configs/standard/commands.rb → feature/plugins/has_inspect.rb} +1 -2
  41. data/lib/convenient_service/feature/plugins.rb +1 -0
  42. data/lib/convenient_service/feature.rb +16 -0
  43. data/lib/convenient_service/logger.rb +11 -12
  44. data/lib/convenient_service/rspec/helpers/classes.rb +0 -2
  45. data/lib/convenient_service/rspec/helpers/stub_entry.rb +23 -5
  46. data/lib/convenient_service/rspec/helpers/stub_service.rb +79 -11
  47. data/lib/convenient_service/rspec/matchers/classes/cache_its_value.rb +2 -1
  48. data/lib/convenient_service/rspec/matchers/classes/delegate_to.rb +3 -5
  49. data/lib/convenient_service/rspec/matchers/classes/include_config.rb +4 -0
  50. data/lib/convenient_service/service/configs/aliases.rb +42 -0
  51. data/lib/convenient_service/service/configs/standard/aliases.rb +24 -0
  52. data/lib/convenient_service/service/configs/standard/v1.rb +17 -0
  53. data/lib/convenient_service/service/configs/standard.rb +50 -25
  54. data/lib/convenient_service/service/core.rb +39 -0
  55. data/lib/convenient_service/service/plugins/aliases.rb +48 -0
  56. data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +33 -2
  57. data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results/concern.rb +34 -0
  58. data/lib/convenient_service/service/plugins/can_have_rspec_stubbed_results.rb +8 -0
  59. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/delete_service_stubbed_result.rb +63 -0
  60. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +15 -10
  61. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_service_stubbed_results_cache.rb +3 -3
  62. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands.rb +2 -0
  63. data/lib/convenient_service/service/plugins/can_have_stubbed_results/concern.rb +25 -0
  64. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_mock.rb +254 -0
  65. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/result_unmock.rb +82 -0
  66. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_stub.rb +135 -0
  67. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities/service_unstub.rb +113 -0
  68. data/lib/convenient_service/service/plugins/can_have_stubbed_results/entities.rb +12 -0
  69. data/lib/convenient_service/service/plugins/can_have_stubbed_results.rb +1 -14
  70. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +84 -0
  71. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +84 -32
  72. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/concern.rb +42 -2
  73. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_called/exceptions.rb +3 -2
  74. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +5 -0
  75. data/lib/convenient_service/service.rb +16 -0
  76. data/lib/convenient_service/specification.rb +42 -12
  77. data/lib/convenient_service/support/backtrace_cleaner.rb +6 -7
  78. data/lib/convenient_service/support/middleware/stack_builder/entities/builders/custom.rb +4 -0
  79. data/lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb +4 -0
  80. data/lib/convenient_service/support/unique_value.rb +4 -1
  81. data/lib/convenient_service/support.rb +13 -0
  82. data/lib/convenient_service/utils/array/find_last.rb +18 -9
  83. data/lib/convenient_service/utils/class/display_name.rb +9 -9
  84. data/lib/convenient_service/utils/enumerable/find_last.rb +48 -0
  85. data/lib/convenient_service/utils/enumerable.rb +20 -0
  86. data/lib/convenient_service/utils/hash/assert_valid_keys.rb +4 -4
  87. data/lib/convenient_service/utils/hash/except.rb +5 -4
  88. data/lib/convenient_service/utils/hash/triple_equality_compare.rb +8 -8
  89. data/lib/convenient_service/utils/kernel/silence_warnings.rb +4 -4
  90. data/lib/convenient_service/utils/module/fetch_own_const.rb +36 -31
  91. data/lib/convenient_service/utils/module/get_namespace.rb +26 -21
  92. data/lib/convenient_service/utils/module/get_own_const.rb +21 -16
  93. data/lib/convenient_service/utils/object/clamp_class.rb +50 -47
  94. data/lib/convenient_service/utils/object/duck_class.rb +84 -81
  95. data/lib/convenient_service/utils/object/get_own_method.rb +1 -1
  96. data/lib/convenient_service/utils/object/instance_variable_delete.rb +0 -3
  97. data/lib/convenient_service/utils/object/instance_variable_fetch.rb +0 -3
  98. data/lib/convenient_service/utils/object/memoize_including_falsy_values.rb +0 -3
  99. data/lib/convenient_service/utils/object/resolve_type.rb +13 -11
  100. data/lib/convenient_service/utils/object/safe_send.rb +2 -0
  101. data/lib/convenient_service/utils/string/enclose.rb +11 -11
  102. data/lib/convenient_service/utils/string/tab.rb +60 -0
  103. data/lib/convenient_service/utils/string.rb +5 -0
  104. data/lib/convenient_service/utils.rb +9 -0
  105. data/lib/convenient_service/version.rb +8 -1
  106. data/lib/convenient_service.rb +232 -14
  107. metadata +37 -754
  108. data/lib/convenient_service/feature/configs/standard/commands/is_feature.rb +0 -39
  109. data/lib/convenient_service/feature/configs/standard/commands/is_feature_class.rb +0 -41
  110. data/lib/convenient_service/rspec/helpers/classes/stub_entry/constants.rb +0 -25
  111. data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/stubbed_feature.rb +0 -128
  112. data/lib/convenient_service/rspec/helpers/classes/stub_entry/entities/value_spec.rb +0 -79
  113. data/lib/convenient_service/rspec/helpers/classes/stub_entry.rb +0 -48
  114. data/lib/convenient_service/rspec/helpers/classes/stub_service/constants.rb +0 -25
  115. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/result_spec.rb +0 -211
  116. data/lib/convenient_service/rspec/helpers/classes/stub_service/entities/stubbed_service.rb +0 -119
  117. data/lib/convenient_service/rspec/helpers/classes/stub_service.rb +0 -43
  118. data/lib/convenient_service/service/configs/standard/commands/is_service.rb +0 -39
  119. data/lib/convenient_service/service/configs/standard/commands/is_service_class.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a82b04aed6d540c497da63b9398dc605319c95b6aeed0152edfa03c3e82f9f0d
4
- data.tar.gz: 68ed1a1f53824b237f3cf322ae0130cec5ee04743368b84c536017f8d676e848
3
+ metadata.gz: dc0b70a8a73f6bffd654e90e8ad332f0132b7ea83255ad56860c6e3ac454492c
4
+ data.tar.gz: e9be9fdaf668c6fdd510b27af3a04b9fa01582891478c95cab72320236926939
5
5
  SHA512:
6
- metadata.gz: 4ff920321871a94fb2424e2d732574494471560fd5d2f7e97abecd44822e755f2de1b38161e5afa31da98b32ff7bd71576d50c1352ef64530ceabaf34f65e372
7
- data.tar.gz: '080d31c61846cb2d53dc771708deddbd0fb84252369baa663b7a57f740d8d082cc6e4d6893bdc3f82ca92653968646c9723b319aee753bdada09d2cf935ad69f'
6
+ metadata.gz: 372f4e96c265835df11321a7e30e2a8aaf5544ab6fea1d9b89084e4f1687a6399dbb72bea80b730fab31c5bc44722e0647260e717f518201c36a5e575f2cf074
7
+ data.tar.gz: 84852e20f09454a0181fc1438205f4ef446aba65d86c3c391838f4b340eb31546fe7e2bdd226da8bfc94c9d2ef80bf5e23c884d00282ef966c5384840f79e207
data/README.md CHANGED
@@ -28,6 +28,8 @@
28
28
  [![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/user?u=31435716&fan_landing=true)
29
29
  [![License: LGPL-3.0](https://img.shields.io/badge/license-LGPL--3.0-yellow.svg)](https://www.gnu.org/licenses/lgpl-3.0.html)
30
30
 
31
+ [![GitHub Repo](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/marian13/convenient_service) [![GitLab Mirror](https://img.shields.io/badge/gitlab-mirror-orange?logo=gitlab)](https://gitlab.com/marian13/convenient_service) [![Codeberg Mirror](https://img.shields.io/badge/codeberg-mirror-green?logo=codeberg)](https://codeberg.org/marian13/convenient_service)
32
+
31
33
  <!-- NOTE: The "Visit Count" and the "Inline Docs" badges are commented since they are failing with errors most of the time -->
32
34
  <!-- ![visitors](https://visitor-badge.glitch.me/badge?page_id=marian13/convenient_service) -->
33
35
  <!-- [![inline docs](http://inch-ci.org/github/marian13/convenient_service.svg?branch=main)](http://inch-ci.org/github/marian13/convenient_service) -->
@@ -41,7 +43,11 @@
41
43
  <!-- logo:end -->
42
44
 
43
45
  <!-- general_description:start -->
44
- Yet another approach to revisit the service object pattern, but this time focusing on the unique, opinionated features.
46
+ Manage complex business logic in Ruby applications using Service Objects with Results and Steps.
47
+
48
+ Hide technical details with Configs, Concerns and Middlewares.
49
+
50
+ Group related code with Features and Entries.
45
51
  <!-- general_description:end -->
46
52
 
47
53
  <!-- warning:start -->
@@ -73,12 +79,10 @@ This library is on the final stage of development before the v1.0.0 version. 90%
73
79
 
74
80
  - Have a look at [Convenient Service Development Wiki](https://github.com/marian13/convenient_service/wiki) for the contribution tutorials.
75
81
 
76
- - [Backlog](https://github.com/marian13/convenient_service/blob/main/BACKLOG.md).
77
-
78
82
  <!-- links:end -->
79
83
 
80
84
  ---
81
85
 
82
86
  <!-- author:start -->
83
- Copyright (c) 2022-2025 Marian Kostyk.
87
+ Copyright (c) 2022-2026 Marian Kostyk.
84
88
  <!-- author:end -->
@@ -9,10 +9,122 @@
9
9
  # @internal
10
10
  # NOTE: Aliases hide the full constants path from the end-users in order to increase DX.
11
11
  # - https://en.wikipedia.org/wiki/User_experience#Developer_experience
12
- #
12
+ ##
13
+
13
14
  module ConvenientService
15
+ ##
16
+ # Convenient Service command (aka operation without results and steps).
17
+ # Useful for utils that are always "successful".
18
+ #
19
+ # @api public
20
+ # @since 1.0.0
21
+ # @return [Class]
22
+ #
23
+ # @example Common usage.
24
+ # class ToBool < ConvenientService::Command
25
+ # attr_reader :object
26
+ #
27
+ # def initialize(object)
28
+ # @object = object
29
+ # end
30
+ #
31
+ # def call
32
+ # !!object
33
+ # end
34
+ # end
35
+ #
36
+ # ToBool.new(42).call
37
+ # # => true
38
+ #
39
+ # ToBool.call(42)
40
+ # # => true
41
+ #
42
+ # ToBool.(42)
43
+ # # => true
44
+ #
45
+ # ToBool[42]
46
+ # # => true
47
+ #
48
+ # @example No need to define class `call` method.
49
+ # class Command < ConvenientService::Command
50
+ # # ...
51
+ #
52
+ # ##
53
+ # # Class `call` method in already defined in `ConvenientService::Command` like so:
54
+ # #
55
+ # # def call(...)
56
+ # # new.call(...)
57
+ # # end
58
+ # ##
59
+ #
60
+ # # ...
61
+ # end
62
+ #
14
63
  Command = ::ConvenientService::Support::Command
64
+
65
+ ##
66
+ # Convenient Service concern (Like Rails concern, but with some customizations).
67
+ #
68
+ # @api public
69
+ # @since 1.0.0
70
+ # @return [Module]
71
+ #
72
+ # @note Expected to be used from Convenient Service plugins.
73
+ #
15
74
  Concern = ::ConvenientService::Support::Concern
75
+
76
+ ##
77
+ # Convenient Service dependency container.
78
+ #
79
+ # @api public
80
+ # @since 1.0.0
81
+ # @return [Module]
82
+ #
83
+ # @example Common usage.
84
+ # module Container
85
+ # include ConvenientService::DependencyContainer::Export
86
+ #
87
+ # export "foo" do |*args|
88
+ # "foo"
89
+ # end
90
+ #
91
+ # export :bar do |**kwargs|
92
+ # "bar"
93
+ # end
94
+ #
95
+ # export :baz do |&block|
96
+ # "baz"
97
+ # end
98
+ # end
99
+ #
100
+ # class User
101
+ # include ConvenientService::DependencyContainer::Import
102
+ #
103
+ # import :foo, from: Container
104
+ # import "bar", as: :custom_bar, from: Container
105
+ # import :baz, as: "namespaced.baz", from: Container
106
+ # end
107
+ #
108
+ # User.new.foo
109
+ # # => "foo"
110
+ #
111
+ # User.new.custom_bar
112
+ # # => "bar"
113
+ #
114
+ # User.new.namespaced.baz
115
+ # # => "baz"
116
+ #
16
117
  DependencyContainer = ::ConvenientService::Support::DependencyContainer
118
+
119
+ ##
120
+ # Convenient Service base result class. Useful as a shortcut for result utilities.
121
+ #
122
+ # @api public
123
+ # @since 1.0.0
124
+ # @return [Class]
125
+ #
126
+ # @example How to check whether an object is a result?
127
+ # ConvenintService::Result.result?(some_object)
128
+ #
17
129
  Result = ::ConvenientService::Service::Plugins::HasJSendResult::Entities::Result
18
130
  end
@@ -6,7 +6,76 @@
6
6
  ##
7
7
 
8
8
  module ConvenientService
9
+ ##
10
+ # Intermediate module/namespace to access plugins. See `Constant Summary` for examples.
11
+ #
12
+ # @api public
13
+ # @since 1.0.0
14
+ # @return [Module]
15
+ #
9
16
  module Plugins
17
+ ##
18
+ # Intermediate module/namespace to access plugins that can be applied to several types of entities.
19
+ #
20
+ # @api public
21
+ # @since 1.0.0
22
+ # @return [Module]
23
+ #
24
+ # @example Common plugin `CanHaveCallbacks` is used by both services and steps.
25
+ # ##
26
+ # # Since the `CanHaveCallbacks` common plugin is included by default by the standard config,
27
+ # # the example below shows how to remove it instead of adding it.
28
+ # #
29
+ # class Service
30
+ # include ConvenientService::Standard::Config
31
+ #
32
+ # concerns do
33
+ # delete ConvenientService::Plugins::Common::CanHaveCallbacks::Concern
34
+ # end
35
+ #
36
+ # middlewares :result do
37
+ # delete ConvenientService::Plugins::Common::CanHaveCallbacks::Middleware
38
+ # end
39
+ #
40
+ # entity :Step do
41
+ # concerns do
42
+ # delete ConvenientService::Plugins::Common::CanHaveCallbacks::Concern
43
+ # end
44
+ #
45
+ # middlewares :result do
46
+ # delete ConvenientService::Plugins::Common::CanHaveCallbacks::Middleware
47
+ # end
48
+ # end
49
+ #
50
+ # ##
51
+ # # Raises since `CanHaveCallbacks` is removed.
52
+ # #
53
+ # before :result do
54
+ # end
55
+ #
56
+ # def result
57
+ # success
58
+ # end
59
+ # end
60
+ #
61
+ # @example Shorter way to remove `CanHaveCallbacks` plugin.
62
+ # ##
63
+ # # Some common plugin groups like `:callbacks` can be removed by config option.
64
+ # #
65
+ # class Service
66
+ # include ConvenientService::Standard::Config.without(:callbacks)
67
+ #
68
+ # ##
69
+ # # Raises since `CanHaveCallbacks` is removed.
70
+ # #
71
+ # before :result do
72
+ # end
73
+ #
74
+ # def result
75
+ # success
76
+ # end
77
+ # end
78
+ #
10
79
  Common = ::ConvenientService::Common::Plugins
11
80
  end
12
81
  end
@@ -22,7 +22,7 @@ module ConvenientService
22
22
  # @return [void]
23
23
  #
24
24
  def initialize(types:)
25
- @types = types.map(&Entities::Type.method(:cast!))
25
+ @types = types.map { |type| Entities::Type.cast!(type) }
26
26
  end
27
27
 
28
28
  ##
@@ -30,7 +30,7 @@ module ConvenientService
30
30
  # @return [Boolean]
31
31
  #
32
32
  def contain_exactly?(other_types)
33
- other_types = other_types.map(&Entities::Type.method(:cast!))
33
+ other_types = other_types.map { |type| Entities::Type.cast!(type) }
34
34
 
35
35
  Utils::Array.contain_exactly?(types, other_types)
36
36
  end
@@ -10,7 +10,7 @@ module ConvenientService
10
10
  module Plugins
11
11
  module HasInstanceProxy
12
12
  module Entities
13
- class InstanceProxy
13
+ class InstanceProxy < ::BasicObject
14
14
  ##
15
15
  # @api private
16
16
  #
@@ -33,13 +33,13 @@ module ConvenientService
33
33
  ##
34
34
  # @return [Class]
35
35
  #
36
- alias_method :instance_proxy_class, :class
37
-
38
- ##
39
- # @return [Class]
36
+ # @internal
37
+ # NOTE: `alias_method :instance_proxy_class, :class` does NOT work, since `BasicObject` does NOT have `class` method. It is defined in `Kernel`.
38
+ # - https://ruby-doc.org/core-3.0.2/Kernel.html#method-i-class
39
+ # - https://ruby-doc.org/core-2.7.0/UnboundMethod.html#method-i-bind_call
40
40
  #
41
- def class
42
- instance_proxy_target.class
41
+ def instance_proxy_class
42
+ ::Kernel.instance_method(:class).bind_call(self)
43
43
  end
44
44
 
45
45
  ##
@@ -49,7 +49,7 @@ module ConvenientService
49
49
  # @return [Boolean, nil]
50
50
  #
51
51
  def ==(other)
52
- return unless other.instance_of?(instance_proxy_class)
52
+ return unless ::Kernel.instance_method(:instance_of?).bind_call(other, instance_proxy_class)
53
53
 
54
54
  return false if instance_proxy_target != other.instance_proxy_target
55
55
 
@@ -6,3 +6,17 @@
6
6
  ##
7
7
 
8
8
  require_relative "common/plugins"
9
+
10
+ module ConvenientService
11
+ ##
12
+ # Intermediate module/namespace to access plugins that can be applied to several types of entities.
13
+ #
14
+ # @api private
15
+ # @since 1.0.0
16
+ # @return [Module]
17
+ #
18
+ # @note Common plugins expected to be used via {ConvenientService::Plugins::Common} alias.
19
+ #
20
+ module Common
21
+ end
22
+ end
@@ -129,6 +129,14 @@ module ConvenientService
129
129
  @options ||= default_options.dup
130
130
  end
131
131
 
132
+ ##
133
+ # @param block [Proc, nil]
134
+ # @return [ConvenientService::Config::Entities::OptionCollection]
135
+ #
136
+ def available_options(&block)
137
+ block ? @available_options = Commands::NormalizeOptions[options: yield] : @available_options ||= empty_options
138
+ end
139
+
132
140
  ##
133
141
  # @param block [Proc, nil]
134
142
  # @return [ConvenientService::Config::Entities::OptionCollection]
@@ -6,8 +6,92 @@
6
6
  ##
7
7
 
8
8
  module ConvenientService
9
+ ##
10
+ # Base class for concern middlewares.
11
+ #
12
+ # @api private
13
+ # @since 1.0.0
14
+ # @return [Class]
15
+ #
9
16
  ConcernMiddleware = ::ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Middleware
10
17
 
18
+ ##
19
+ # Base class for method middlewares using classic `stack.call`.
20
+ #
21
+ # @api public
22
+ # @since 1.0.0
23
+ # @return [Class]
24
+ #
25
+ # @note Prefer `ConvenientService::MethodChainMiddleware`.
26
+ #
27
+ # @example Common usage.
28
+ # class Middleware < ConvenientService::MethodClassicMiddleware
29
+ # def call(env)
30
+ # p env
31
+ #
32
+ # value = stack.call(env)
33
+ #
34
+ # p value
35
+ #
36
+ # value
37
+ # end
38
+ # end
39
+ #
40
+ # class Service
41
+ # include ConvenientService::Standard::Config
42
+ #
43
+ # middlewares :result do
44
+ # insert_before 0, Middleware
45
+ # end
46
+ #
47
+ # def result
48
+ # success
49
+ # end
50
+ # end
51
+ #
52
+ # Service.result
53
+ # # {args: [], kwargs: {}, block: nil, entity: <Service>, method: :result}
54
+ # # <Service::Result status: :success>
55
+ # # => <Service::Result status: :success>
56
+ #
11
57
  MethodClassicMiddleware = ::ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Classic
58
+
59
+ ##
60
+ # Base class for method middlewares using `chain.next`.
61
+ #
62
+ # @api public
63
+ # @since 1.0.0
64
+ # @return [Class]
65
+ #
66
+ # @example Common usage.
67
+ # class Middleware < ConvenientService::MethodChainMiddleware
68
+ # def next(*args, **kwargs, &block)
69
+ # p [args, kwargs, block]
70
+ #
71
+ # value = chain.next(*args, **kwargs, &block)
72
+ #
73
+ # p value
74
+ #
75
+ # value
76
+ # end
77
+ # end
78
+ #
79
+ # class Service
80
+ # include ConvenientService::Standard::Config
81
+ #
82
+ # middlewares :result do
83
+ # insert_before 0, Middleware
84
+ # end
85
+ #
86
+ # def result
87
+ # success
88
+ # end
89
+ # end
90
+ #
91
+ # Service.result
92
+ # # {args: [], kwargs: {}, block: nil, entity: <Service>, method: :result}
93
+ # # <Service::Result status: :success>
94
+ # # => <Service::Result status: :success>
95
+ #
12
96
  MethodChainMiddleware = ::ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middlewares::Chain
13
97
  end
@@ -9,7 +9,10 @@
9
9
  # This file loads built-in dependencies (from Ruby standard library).
10
10
  #
11
11
  # @internal
12
- # https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
12
+ # - https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
13
+ #
14
+ # NOTE: Ensure all `require` for built-in dependencies are explicit.
15
+ # - https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/RedundantRequireStatement
13
16
  ##
14
17
 
15
18
  ##
@@ -65,4 +68,15 @@ require "singleton"
65
68
  #
66
69
  # @!visibility private
67
70
  #
71
+ # rubocop:disable Lint/RedundantRequireStatement
68
72
  require "thread"
73
+ # rubocop:enable Lint/RedundantRequireStatement
74
+
75
+ ##
76
+ # @internal
77
+ # - https://ruby-doc.org/stdlib-2.7.0/libdoc/set/rdoc/Set.html
78
+ # - https://github.com/ruby/set
79
+ #
80
+ # @!visibility private
81
+ #
82
+ require "set"
@@ -25,12 +25,6 @@ require "rubygems"
25
25
  #
26
26
  require_relative "queries"
27
27
 
28
- ##
29
- # `ConvenientService::Dependencies` can dynamically require plugins/extensions that have external dependencies.
30
- #
31
- # @internal
32
- # https://github.com/marian13/convenient_service/wiki/Docs:-Dependencies
33
- #
34
28
  module ConvenientService
35
29
  module Dependencies
36
30
  extend Queries
@@ -0,0 +1,55 @@
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 Dependencies
10
+ module Queries
11
+ module Gems
12
+ ##
13
+ # @api private
14
+ #
15
+ class Minitest
16
+ class << self
17
+ ##
18
+ # @return [Boolean]
19
+ #
20
+ # @internal
21
+ # `Style/TernaryParentheses` is disabled since `defined?` has too low priority without parentheses.
22
+ #
23
+ # rubocop:disable Style/TernaryParentheses
24
+ def loaded?
25
+ (defined? ::Minitest) ? true : false
26
+ end
27
+ # rubocop:enable Style/TernaryParentheses
28
+
29
+ ##
30
+ # @return [ConvenientService::Dependencies::Queries::Version]
31
+ #
32
+ # @internal
33
+ # - https://github.com/minitest/minitest/blob/master/lib/minitest.rb
34
+ #
35
+ def version
36
+ loaded? ? Version.new(::Minitest::VERSION) : Version.null_version
37
+ end
38
+
39
+ ##
40
+ # @internal
41
+ # Minitest does NOT have `::RSpec.current_example` equivalent.
42
+ # -
43
+ #
44
+ # def current_example
45
+ # return unless loaded?
46
+ #
47
+ # # ...
48
+ # end
49
+ ##
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -30,7 +30,7 @@ module ConvenientService
30
30
  # @return [ConvenientService::Dependencies::Queries::Version]
31
31
  #
32
32
  # @internal
33
- # https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/version.rb
33
+ # - https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/version.rb
34
34
  #
35
35
  def version
36
36
  loaded? ? Version.new(::RSpec::Core::Version::STRING) : Version.null_version
@@ -8,4 +8,6 @@
8
8
  require_relative "gems/active_model"
9
9
  require_relative "gems/logger"
10
10
  require_relative "gems/paint"
11
+
12
+ require_relative "gems/minitest"
11
13
  require_relative "gems/rspec"
@@ -86,7 +86,7 @@ module ConvenientService
86
86
  # @see https://github.com/rdp/os
87
87
  #
88
88
  def jruby?
89
- engine.match?(/jruby/)
89
+ engine.include?("jruby")
90
90
  end
91
91
 
92
92
  ##
@@ -95,7 +95,7 @@ module ConvenientService
95
95
  # @return [Boolean]
96
96
  #
97
97
  def truffleruby?
98
- engine.match?(/truffleruby/)
98
+ engine.include?("truffleruby")
99
99
  end
100
100
 
101
101
  ##