convenient_service 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/ROADMAP.md +2 -0
- data/lib/convenient_service/aliases.rb +9 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +19 -0
- data/lib/convenient_service/configs/minimal.rb +176 -0
- data/lib/convenient_service/configs/standard.rb +16 -104
- data/lib/convenient_service/configs.rb +1 -0
- data/lib/convenient_service/dependencies.rb +8 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +5 -5
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +7 -7
- data/lib/convenient_service/rspec/helpers/custom/ignoring_error.rb +3 -0
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +29 -3
- data/lib/convenient_service/rspec/matchers/custom/results/base.rb +5 -0
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +3 -3
- data/lib/convenient_service/service/plugins/has_result/constants.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +13 -0
- data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +37 -2
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +80 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_cause.rb +78 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +169 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_line.rb +40 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands.rb +7 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/constants.rb +13 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +58 -0
- data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb +5 -0
- data/lib/convenient_service/support/undefined.rb +9 -0
- data/lib/convenient_service/support.rb +2 -0
- data/lib/convenient_service/version.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d53f96dab5d2b97b26168f4859dc0daefe41c8768e83e607d13234c2c7d77101
|
4
|
+
data.tar.gz: c6d5a9d30e5c3c768f556eb7d84b558099fcbeb96dbff655b7bd2b553435a26a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3fb867003d44c6786446fdb2baac4550bd6ac8f34ee9196ee310912c4eb2084f40dc731dce8a2af7ac8a963d6a3579c6e886ad28251c4bf5a9a08ca290a6d2
|
7
|
+
data.tar.gz: e24704e463ac31d3f65a4c9a5777617157bdebb62ab785e92f3f18125d8968e5c3a6d44368553c706c9f8bab0ce7bd8f938ce53ebc1df68585493738533ef2cb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.8.0](https://github.com/marian13/convenient_service/compare/v0.7.0...v0.8.0) (2023-02-20)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* **aliases:** expose middlewares ([aacb6fd](https://github.com/marian13/convenient_service/commit/aacb6fda4c63e1d82e33c523885bd61397cfb583))
|
9
|
+
* **configs:** introduce Minimal config ([70b0ca8](https://github.com/marian13/convenient_service/commit/70b0ca82679fc89099aee733d91807e371bbed39))
|
10
|
+
* **rescues_result_unhandled_exceptions:** introduce rescues_result_unhandled_exceptions ([fd0b444](https://github.com/marian13/convenient_service/commit/fd0b4447e5abf81d971cd93a8333a89b363ef1ff))
|
11
|
+
* **rescues_result_unhandled_exceptions:** return original exception in data + formatted exception as message ([45bc55e](https://github.com/marian13/convenient_service/commit/45bc55ec245df1b95769be761337a3cb2558a878))
|
12
|
+
* **undefined:** introduce undefined ([2f93bdc](https://github.com/marian13/convenient_service/commit/2f93bdc86d81c9a819bbc1c4a76a0ef291a59b17))
|
13
|
+
* **wrap_method:** introduce WrappedMethod#chain_exception ([1db33af](https://github.com/marian13/convenient_service/commit/1db33afc3a0e0713700b0bf5385900085af0a2df))
|
14
|
+
|
15
|
+
|
16
|
+
### Bug Fixes
|
17
|
+
|
18
|
+
* **wrapped_method:** define chain value even if chain.next raises an exception ([8c4cf95](https://github.com/marian13/convenient_service/commit/8c4cf9534a07e9614fdc73f0d0c019f9c3f0ea54))
|
19
|
+
* **wrapped_method:** reraise rescued exception ([31f7ab6](https://github.com/marian13/convenient_service/commit/31f7ab6df0b34980656942992d3ecf7a67461d06))
|
20
|
+
|
3
21
|
## [0.7.0](https://github.com/marian13/convenient_service/compare/v0.6.0...v0.7.0) (2023-02-13)
|
4
22
|
|
5
23
|
|
data/ROADMAP.md
CHANGED
@@ -75,5 +75,7 @@
|
|
75
75
|
| Low | 🚧 | Rubocop cop that complains when a service name does NOT start with a verb | |
|
76
76
|
| Low | 🚧 | Generator to create a spec default structure | |
|
77
77
|
| Low | 🚧 | Rubocop cop that complains when a service does NOT have its own suite of specs | |
|
78
|
+
| High | 🚧 | Add specs for `WrappedMethod#call` | |
|
79
|
+
| High | 🚧 | Check whether ignoring error was used properly | |
|
78
80
|
|
79
81
|
Search for `TODO`s in the codebase for more tasks.
|
@@ -1,7 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
##
|
4
|
+
# @internal
|
5
|
+
# NOTE: Aliases hide the full constants path from the end-users in order to increase DX.
|
6
|
+
# - https://en.wikipedia.org/wiki/User_experience#Developer_experience
|
7
|
+
#
|
3
8
|
module ConvenientService
|
4
9
|
Command = ::ConvenientService::Support::Command
|
5
10
|
Concern = ::ConvenientService::Support::Concern
|
6
11
|
DependencyContainer = ::ConvenientService::Support::DependencyContainer
|
12
|
+
|
13
|
+
ClassicMiddleware = ::ConvenientService::Core::Entities::ClassicMiddleware
|
14
|
+
ConcernMiddleware = ::ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Middleware
|
15
|
+
MethodChainMiddleware = ::ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware
|
7
16
|
end
|
@@ -13,6 +13,25 @@ module ConvenientService
|
|
13
13
|
# @since 0.2.0
|
14
14
|
#
|
15
15
|
# @internal
|
16
|
+
# NOTE: `allocate` creates an uninitialized object and allocates memory for it.
|
17
|
+
#
|
18
|
+
# NOTE: Pseudocode for default `new` implementation.
|
19
|
+
# def new
|
20
|
+
# instance = allocate
|
21
|
+
#
|
22
|
+
# instance.send(:initialize)
|
23
|
+
#
|
24
|
+
# instance
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# NOTE: Code for `new_without_initialize`.
|
28
|
+
# def new_without_initialize
|
29
|
+
# allocate
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# NOTE: `create` is used instead of `new` in order to avoid the accidental feeling that `new_without_initialize` is Ruby's built-in method.
|
33
|
+
#
|
34
|
+
# NOTE: Check the following links for more info.
|
16
35
|
# - https://ruby-doc.org/core-2.5.0/Class.html#method-i-allocate
|
17
36
|
# - https://frontdeveloper.pl/2018/11/ruby-allocate-method/
|
18
37
|
#
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ConvenientService
|
4
|
+
module Configs
|
5
|
+
##
|
6
|
+
# Defines minimal configuration that adds a constructor, JSend-inspired result, steps, basic inspects, and internals to services.
|
7
|
+
#
|
8
|
+
# @note: This config is NOT intented for the end-user usage. Use `Standard` instead.
|
9
|
+
#
|
10
|
+
# @internal
|
11
|
+
# Heavily used in specs to test concerns and middlewares in isolation.
|
12
|
+
#
|
13
|
+
module Minimal
|
14
|
+
include Support::Concern
|
15
|
+
|
16
|
+
##
|
17
|
+
# @internal
|
18
|
+
# IMPORTANT: Order of plugins matters.
|
19
|
+
#
|
20
|
+
# NOTE: `class_exec` (that is used under the hood by `included`) defines `class Result` in the global namespace.
|
21
|
+
# That is why `class self::Result` is used.
|
22
|
+
# - https://stackoverflow.com/a/51965126/12201472
|
23
|
+
#
|
24
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
25
|
+
included do
|
26
|
+
include Core
|
27
|
+
|
28
|
+
concerns do
|
29
|
+
use Plugins::Common::HasInternals::Concern
|
30
|
+
|
31
|
+
use Plugins::Service::HasInspect::Concern
|
32
|
+
|
33
|
+
use Plugins::Common::HasConstructor::Concern
|
34
|
+
use Plugins::Common::HasConstructorWithoutInitialize::Concern
|
35
|
+
|
36
|
+
use Plugins::Service::HasResult::Concern
|
37
|
+
use Plugins::Service::HasResultSteps::Concern
|
38
|
+
end
|
39
|
+
|
40
|
+
middlewares :initialize do
|
41
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
42
|
+
end
|
43
|
+
|
44
|
+
middlewares :result do
|
45
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
46
|
+
|
47
|
+
use Plugins::Service::HasResult::Middleware
|
48
|
+
use Plugins::Service::HasResultSteps::Middleware
|
49
|
+
end
|
50
|
+
|
51
|
+
middlewares :step do
|
52
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
53
|
+
end
|
54
|
+
|
55
|
+
middlewares :success do
|
56
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
57
|
+
end
|
58
|
+
|
59
|
+
middlewares :failure do
|
60
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
61
|
+
end
|
62
|
+
|
63
|
+
middlewares :error do
|
64
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
65
|
+
end
|
66
|
+
|
67
|
+
middlewares :result, scope: :class do
|
68
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
69
|
+
end
|
70
|
+
|
71
|
+
middlewares :step, scope: :class do
|
72
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
73
|
+
end
|
74
|
+
|
75
|
+
class self::Internals
|
76
|
+
include Core
|
77
|
+
|
78
|
+
concerns do
|
79
|
+
use Plugins::Internals::HasCache::Concern
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class self::Result
|
84
|
+
include Core
|
85
|
+
|
86
|
+
concerns do
|
87
|
+
use Plugins::Common::HasInternals::Concern
|
88
|
+
|
89
|
+
use Plugins::Result::HasInspect::Concern
|
90
|
+
|
91
|
+
use Plugins::Common::HasConstructor::Concern
|
92
|
+
|
93
|
+
use Plugins::Result::HasJsendStatusAndAttributes::Concern
|
94
|
+
end
|
95
|
+
|
96
|
+
middlewares :initialize do
|
97
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
98
|
+
|
99
|
+
use Plugins::Result::HasJsendStatusAndAttributes::Middleware
|
100
|
+
end
|
101
|
+
|
102
|
+
middlewares :success? do
|
103
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
104
|
+
end
|
105
|
+
|
106
|
+
middlewares :failure? do
|
107
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
108
|
+
end
|
109
|
+
|
110
|
+
middlewares :error? do
|
111
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
112
|
+
end
|
113
|
+
|
114
|
+
middlewares :not_success? do
|
115
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
116
|
+
end
|
117
|
+
|
118
|
+
middlewares :not_failure? do
|
119
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
120
|
+
end
|
121
|
+
|
122
|
+
middlewares :not_error? do
|
123
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
124
|
+
end
|
125
|
+
|
126
|
+
middlewares :data do
|
127
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
128
|
+
end
|
129
|
+
|
130
|
+
middlewares :message do
|
131
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
132
|
+
end
|
133
|
+
|
134
|
+
middlewares :code do
|
135
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
136
|
+
end
|
137
|
+
|
138
|
+
middlewares :to_kwargs do
|
139
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
140
|
+
end
|
141
|
+
|
142
|
+
class self::Internals
|
143
|
+
include Core
|
144
|
+
|
145
|
+
concerns do
|
146
|
+
use Plugins::Internals::HasCache::Concern
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class self::Step
|
152
|
+
include Core
|
153
|
+
|
154
|
+
concerns do
|
155
|
+
use Plugins::Common::HasInternals::Concern
|
156
|
+
|
157
|
+
use Plugins::Step::HasInspect::Concern
|
158
|
+
end
|
159
|
+
|
160
|
+
middlewares :calculate_result do
|
161
|
+
use Plugins::Common::NormalizesEnv::Middleware
|
162
|
+
end
|
163
|
+
|
164
|
+
class self::Internals
|
165
|
+
include Core
|
166
|
+
|
167
|
+
concerns do
|
168
|
+
use Plugins::Internals::HasCache::Concern
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -2,54 +2,47 @@
|
|
2
2
|
|
3
3
|
module ConvenientService
|
4
4
|
module Configs
|
5
|
+
##
|
6
|
+
# Default configuration for the user-defined services.
|
7
|
+
#
|
5
8
|
module Standard
|
6
9
|
include Support::Concern
|
7
10
|
|
8
11
|
##
|
9
|
-
#
|
12
|
+
# @internal
|
13
|
+
# IMPORTANT: Order of plugins matters.
|
10
14
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# https://stackoverflow.com/a/51965126/12201472
|
15
|
+
# NOTE: `class_exec` (that is used under the hood by `included`) defines `class Result` in the global namespace.
|
16
|
+
# That is why `class self::Result` is used.
|
17
|
+
# - https://stackoverflow.com/a/51965126/12201472
|
15
18
|
#
|
16
19
|
# rubocop:disable Lint/ConstantDefinitionInBlock
|
17
20
|
included do
|
18
|
-
include
|
21
|
+
include Configs::Minimal
|
19
22
|
|
20
23
|
concerns do
|
21
|
-
use Plugins::Common::HasInternals::Concern
|
22
|
-
use Plugins::Common::HasConstructor::Concern
|
23
|
-
use Plugins::Common::HasConstructorWithoutInitialize::Concern
|
24
|
-
|
25
24
|
use Plugins::Common::CachesConstructorParams::Concern
|
26
25
|
use Plugins::Common::CanBeCopied::Concern
|
27
|
-
use Plugins::Service::HasResult::Concern
|
28
|
-
use Plugins::Service::HasResultShortSyntax::Concern
|
29
|
-
use Plugins::Service::HasResultSteps::Concern
|
30
26
|
use Plugins::Service::CanRecalculateResult::Concern
|
27
|
+
use Plugins::Service::HasResultShortSyntax::Concern
|
31
28
|
use Plugins::Service::HasResultStatusCheckShortSyntax::Concern
|
32
29
|
|
33
30
|
use Plugins::Common::HasCallbacks::Concern
|
34
31
|
use Plugins::Common::HasAroundCallbacks::Concern
|
35
|
-
|
36
|
-
use Plugins::Service::HasInspect::Concern
|
37
32
|
end
|
38
33
|
|
39
34
|
middlewares :initialize do
|
40
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
41
|
-
|
42
35
|
use Plugins::Common::CachesConstructorParams::Middleware
|
43
36
|
end
|
44
37
|
|
45
38
|
middlewares :result do
|
46
|
-
|
39
|
+
insert_before \
|
40
|
+
Plugins::Service::HasResult::Middleware,
|
41
|
+
Plugins::Common::HasCallbacks::Middleware
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
use Plugins::Service::HasResult::Middleware
|
52
|
-
use Plugins::Service::HasResultSteps::Middleware
|
43
|
+
insert_after \
|
44
|
+
Plugins::Common::HasCallbacks::Middleware,
|
45
|
+
Plugins::Common::HasAroundCallbacks::Middleware
|
53
46
|
|
54
47
|
use Plugins::Service::RaisesOnDoubleResult::Middleware
|
55
48
|
|
@@ -57,167 +50,86 @@ module ConvenientService
|
|
57
50
|
end
|
58
51
|
|
59
52
|
middlewares :step do
|
60
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
61
|
-
|
62
53
|
use Plugins::Common::HasCallbacks::Middleware
|
63
54
|
use Plugins::Common::HasAroundCallbacks::Middleware
|
64
55
|
end
|
65
56
|
|
66
57
|
middlewares :success do
|
67
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
68
|
-
|
69
58
|
use Plugins::Service::HasResultShortSyntax::Success::Middleware
|
70
59
|
end
|
71
60
|
|
72
61
|
middlewares :failure do
|
73
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
74
|
-
|
75
62
|
use Plugins::Service::HasResultShortSyntax::Failure::Middleware
|
76
63
|
end
|
77
64
|
|
78
65
|
middlewares :error do
|
79
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
80
|
-
|
81
66
|
use Plugins::Service::HasResultShortSyntax::Error::Middleware
|
82
67
|
end
|
83
68
|
|
84
|
-
middlewares :result, scope: :class do
|
85
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
86
|
-
end
|
87
|
-
|
88
69
|
middlewares :step, scope: :class do
|
89
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
90
|
-
|
91
70
|
use Plugins::Service::HasResultMethodSteps::Middleware
|
92
71
|
end
|
93
72
|
|
94
|
-
class self::Internals
|
95
|
-
include Core
|
96
|
-
|
97
|
-
concerns do
|
98
|
-
use Plugins::Internals::HasCache::Concern
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
73
|
class self::Result
|
103
|
-
include Core
|
104
|
-
|
105
74
|
concerns do
|
106
|
-
use Plugins::Common::HasInternals::Concern
|
107
|
-
use Plugins::Common::HasConstructor::Concern
|
108
|
-
|
109
|
-
use Plugins::Result::HasJsendStatusAndAttributes::Concern
|
110
|
-
|
111
75
|
use Plugins::Result::HasResultShortSyntax::Concern
|
112
76
|
use Plugins::Result::CanRecalculateResult::Concern
|
113
77
|
|
114
78
|
use Plugins::Result::HasStep::Concern
|
115
79
|
use Plugins::Result::CanHaveParentResult::Concern
|
116
|
-
|
117
|
-
use Plugins::Result::HasInspect::Concern
|
118
80
|
end
|
119
81
|
|
120
82
|
middlewares :initialize do
|
121
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
122
|
-
|
123
|
-
use Plugins::Result::HasJsendStatusAndAttributes::Middleware
|
124
|
-
|
125
83
|
use Plugins::Result::HasStep::Initialize::Middleware
|
126
84
|
use Plugins::Result::CanHaveParentResult::Initialize::Middleware
|
127
85
|
end
|
128
86
|
|
129
87
|
middlewares :success? do
|
130
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
131
|
-
|
132
88
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
133
89
|
end
|
134
90
|
|
135
91
|
middlewares :failure? do
|
136
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
137
|
-
|
138
92
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
139
93
|
end
|
140
94
|
|
141
95
|
middlewares :error? do
|
142
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
143
|
-
|
144
96
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
145
97
|
end
|
146
98
|
|
147
99
|
middlewares :not_success? do
|
148
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
149
|
-
|
150
100
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
151
101
|
end
|
152
102
|
|
153
103
|
middlewares :not_failure? do
|
154
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
155
|
-
|
156
104
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
157
105
|
end
|
158
106
|
|
159
107
|
middlewares :not_error? do
|
160
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
161
|
-
|
162
108
|
use Plugins::Result::MarksResultStatusAsChecked::Middleware
|
163
109
|
end
|
164
110
|
|
165
111
|
middlewares :data do
|
166
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
167
|
-
|
168
112
|
use Plugins::Result::RaisesOnNotCheckedResultStatus::Middleware
|
169
113
|
end
|
170
114
|
|
171
115
|
middlewares :message do
|
172
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
173
|
-
|
174
116
|
use Plugins::Result::RaisesOnNotCheckedResultStatus::Middleware
|
175
117
|
end
|
176
118
|
|
177
119
|
middlewares :code do
|
178
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
179
|
-
|
180
120
|
use Plugins::Result::RaisesOnNotCheckedResultStatus::Middleware
|
181
121
|
end
|
182
122
|
|
183
123
|
middlewares :to_kwargs do
|
184
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
185
|
-
|
186
124
|
use Plugins::Result::HasStep::ToKwargs::Middleware
|
187
125
|
use Plugins::Result::CanHaveParentResult::ToKwargs::Middleware
|
188
126
|
end
|
189
|
-
|
190
|
-
class self::Internals
|
191
|
-
include Core
|
192
|
-
|
193
|
-
concerns do
|
194
|
-
use Plugins::Internals::HasCache::Concern
|
195
|
-
end
|
196
|
-
end
|
197
127
|
end
|
198
128
|
|
199
129
|
class self::Step
|
200
|
-
include Core
|
201
|
-
|
202
|
-
concerns do
|
203
|
-
use Plugins::Common::HasInternals::Concern
|
204
|
-
|
205
|
-
use Plugins::Step::HasInspect::Concern
|
206
|
-
end
|
207
|
-
|
208
130
|
middlewares :calculate_result do
|
209
|
-
use Plugins::Common::NormalizesEnv::Middleware
|
210
|
-
|
211
131
|
use Plugins::Step::CanHaveParentResult::Middleware
|
212
132
|
end
|
213
|
-
|
214
|
-
class self::Internals
|
215
|
-
include Core
|
216
|
-
|
217
|
-
concerns do
|
218
|
-
use Plugins::Internals::HasCache::Concern
|
219
|
-
end
|
220
|
-
end
|
221
133
|
end
|
222
134
|
|
223
135
|
if Dependencies.rspec.loaded?
|
@@ -75,6 +75,14 @@ module ConvenientService
|
|
75
75
|
require_relative "service/plugins/has_result_params_validations/using_dry_validation"
|
76
76
|
end
|
77
77
|
|
78
|
+
##
|
79
|
+
# @return [Boolean]
|
80
|
+
# @note Expected to be called from app entry points like `initializers` in Rails.
|
81
|
+
#
|
82
|
+
def require_rescues_result_unhandled_exceptions
|
83
|
+
require_relative "service/plugins/rescues_result_unhandled_exceptions"
|
84
|
+
end
|
85
|
+
|
78
86
|
##
|
79
87
|
# @return [Boolean]
|
80
88
|
# @note Expected to be called from `irb`, `pry`, `spec_helper.rb`, etc.
|
@@ -16,26 +16,26 @@ module ConvenientService
|
|
16
16
|
|
17
17
|
included do |service_class|
|
18
18
|
service_class.class_exec do
|
19
|
-
include
|
19
|
+
include ConvenientService::Standard::Config
|
20
20
|
|
21
21
|
##
|
22
22
|
# NOTE: `AssignsAttributesInConstructor::UsingDryInitializer` plugin.
|
23
23
|
#
|
24
24
|
concerns do
|
25
|
-
use Plugins::Common::AssignsAttributesInConstructor::UsingDryInitializer::Concern
|
25
|
+
use ConvenientService::Plugins::Common::AssignsAttributesInConstructor::UsingDryInitializer::Concern
|
26
26
|
end
|
27
27
|
|
28
28
|
##
|
29
29
|
# NOTE: `HasResultParamsValidations::UsingDryValidation` plugin.
|
30
30
|
#
|
31
31
|
concerns do
|
32
|
-
use Plugins::Service::HasResultParamsValidations::UsingDryValidation::Concern
|
32
|
+
use ConvenientService::Plugins::Service::HasResultParamsValidations::UsingDryValidation::Concern
|
33
33
|
end
|
34
34
|
|
35
35
|
middlewares :result do
|
36
36
|
insert_before \
|
37
|
-
Plugins::Service::HasResult::Middleware,
|
38
|
-
Plugins::Service::HasResultParamsValidations::UsingDryValidation::Middleware
|
37
|
+
ConvenientService::Plugins::Service::HasResult::Middleware,
|
38
|
+
ConvenientService::Plugins::Service::HasResultParamsValidations::UsingDryValidation::Middleware
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -16,37 +16,37 @@ module ConvenientService
|
|
16
16
|
|
17
17
|
included do |service_class|
|
18
18
|
service_class.class_exec do
|
19
|
-
include
|
19
|
+
include ConvenientService::Standard::Config
|
20
20
|
|
21
21
|
##
|
22
22
|
# NOTE: `AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment` plugin.
|
23
23
|
#
|
24
24
|
concerns do
|
25
|
-
use Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Concern
|
25
|
+
use ConvenientService::Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Concern
|
26
26
|
end
|
27
27
|
|
28
28
|
middlewares :initialize do
|
29
|
-
use Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Middleware
|
29
|
+
use ConvenientService::Plugins::Common::AssignsAttributesInConstructor::UsingActiveModelAttributeAssignment::Middleware
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
33
|
# NOTE: `HasAttributes::UsingActiveModelAttributes` plugin.
|
34
34
|
#
|
35
35
|
concerns do
|
36
|
-
use Plugins::Common::HasAttributes::UsingActiveModelAttributes::Concern
|
36
|
+
use ConvenientService::Plugins::Common::HasAttributes::UsingActiveModelAttributes::Concern
|
37
37
|
end
|
38
38
|
|
39
39
|
##
|
40
40
|
# NOTE: `HasResultParamsValidations::UsingActiveModelValidations` plugin.
|
41
41
|
#
|
42
42
|
concerns do
|
43
|
-
use Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Concern
|
43
|
+
use ConvenientService::Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Concern
|
44
44
|
end
|
45
45
|
|
46
46
|
middlewares :result do
|
47
47
|
insert_before \
|
48
|
-
Plugins::Service::HasResult::Middleware,
|
49
|
-
Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Middleware
|
48
|
+
ConvenientService::Plugins::Service::HasResult::Middleware,
|
49
|
+
ConvenientService::Plugins::Service::HasResultParamsValidations::UsingActiveModelValidations::Middleware
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -35,9 +35,25 @@ module ConvenientService
|
|
35
35
|
#
|
36
36
|
stack.use(
|
37
37
|
proc do |env|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
@chain_arguments = {args: env[:args], kwargs: env[:kwargs], block: env[:block]}
|
39
|
+
|
40
|
+
##
|
41
|
+
# IMPORTANT: Forces Ruby to define `@chain_value` instance variable.
|
42
|
+
#
|
43
|
+
# NOTE: If `@chain_value` is still set to `Support::UNDEFINED` after running the begin block - an exception was raised by `chain.next`. See `chain_called?` for more info.
|
44
|
+
#
|
45
|
+
@chain_value = Support::UNDEFINED
|
46
|
+
|
47
|
+
begin
|
48
|
+
@chain_value = entity.__send__(method, *env[:args], **env[:kwargs], &env[:block])
|
49
|
+
rescue => exception
|
50
|
+
@chain_exception = exception
|
51
|
+
|
52
|
+
##
|
53
|
+
# NOTE: `raise` with no args inside `rescue` reraises rescued exception.
|
54
|
+
#
|
55
|
+
raise
|
56
|
+
end
|
41
57
|
end
|
42
58
|
)
|
43
59
|
end
|
@@ -107,6 +123,16 @@ module ConvenientService
|
|
107
123
|
|
108
124
|
@chain_arguments[:block]
|
109
125
|
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# @return [StandardError, nil]
|
129
|
+
# @raise [ConvenientService::RSpec::Helpers::Custom::WrapMethod::Errors::ChainAttributePreliminaryAccess]
|
130
|
+
#
|
131
|
+
def chain_exception
|
132
|
+
raise Errors::ChainAttributePreliminaryAccess.new(attribute: :exception) unless chain_called?
|
133
|
+
|
134
|
+
@chain_exception
|
135
|
+
end
|
110
136
|
end
|
111
137
|
end
|
112
138
|
end
|
@@ -26,7 +26,12 @@ module ConvenientService
|
|
26
26
|
rules = []
|
27
27
|
|
28
28
|
rules << ->(result) { result.class.include?(Service::Plugins::HasResult::Entities::Result::Concern) }
|
29
|
+
|
30
|
+
##
|
31
|
+
# IMPORTANT: Result status is NOT marked as checked intentionally, since it is a mutable operation.
|
32
|
+
#
|
29
33
|
rules << ->(result) { result.status.in?(statuses) }
|
34
|
+
|
30
35
|
rules << ->(result) { result.service.instance_of?(service_class) } if used_of_service?
|
31
36
|
rules << ->(result) { Commands::MatchResultStep.call(result: result, step: step) } if used_of_step?
|
32
37
|
rules << ->(result) { result.unsafe_data == data } if used_data?
|