convenient_service 0.23.0 → 0.25.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/convenient_service/dependencies/queries/version.rb +18 -0
  3. data/lib/convenient_service/dependencies/queries.rb +4 -2
  4. data/lib/convenient_service/extras/rspec.rb +1 -1
  5. data/lib/convenient_service/logger.rb +6 -3
  6. data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/error/commands/generate_got_jsend_attributes_part.rb +1 -1
  7. data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/failure/commands/generate_got_jsend_attributes_part.rb +1 -1
  8. data/lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/success/commands/generate_got_jsend_attributes_part.rb +1 -1
  9. data/lib/convenient_service/rspec/matchers/classes/results/be_error.rb +1 -1
  10. data/lib/convenient_service/rspec/matchers/classes/results/be_failure.rb +1 -1
  11. data/lib/convenient_service/rspec/matchers/classes/results/be_not_error.rb +2 -2
  12. data/lib/convenient_service/rspec/matchers/classes/results/be_not_failure.rb +2 -2
  13. data/lib/convenient_service/rspec/matchers/classes/results/be_not_success.rb +2 -2
  14. data/lib/convenient_service/rspec/matchers/classes/results/be_success.rb +1 -1
  15. data/lib/convenient_service/service/configs/standard.rb +11 -3
  16. data/lib/convenient_service/service/plugins/can_have_after_step_callbacks/middleware.rb +5 -1
  17. data/lib/convenient_service/service/plugins/can_have_around_step_callbacks/middleware.rb +1 -1
  18. data/lib/convenient_service/service/plugins/can_have_before_step_callbacks/middleware.rb +1 -1
  19. data/lib/convenient_service/service/plugins/can_have_connected_steps/concern.rb +1 -6
  20. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/scalar.rb +1 -1
  21. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_backtrace.rb +1 -1
  22. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_cause.rb +1 -1
  23. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_class.rb +1 -1
  24. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_exception.rb +2 -2
  25. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_line.rb +1 -1
  26. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands/format_message.rb +1 -1
  27. data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/constants.rb +1 -1
  28. data/lib/convenient_service/service/plugins/can_have_formatted_exceptions.rb +35 -0
  29. data/lib/convenient_service/service/plugins/can_have_handled_exceptions/concern.rb +34 -0
  30. data/lib/convenient_service/service/plugins/can_have_handled_exceptions.rb +8 -0
  31. data/lib/convenient_service/service/plugins/can_have_inline_services/concern.rb +29 -0
  32. data/lib/convenient_service/service/plugins/can_have_inline_services/entities/proxy.rb +205 -0
  33. data/lib/convenient_service/service/plugins/{can_have_steps/entities/step/plugins/can_be_completed.rb → can_have_inline_services/entities.rb} +1 -1
  34. data/lib/convenient_service/service/plugins/can_have_inline_services/exceptions.rb +30 -0
  35. data/lib/convenient_service/service/plugins/can_have_inline_services.rb +36 -0
  36. data/lib/convenient_service/service/plugins/can_have_sequential_steps/concern.rb +2 -0
  37. data/lib/convenient_service/service/plugins/can_have_sequential_steps/middleware.rb +1 -5
  38. data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +1 -6
  39. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +5 -8
  40. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/proc.rb +1 -1
  41. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/callers/raw.rb +1 -1
  42. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +1 -1
  43. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/key.rb +1 -1
  44. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +13 -0
  45. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/{can_be_completed → can_be_evaluated}/concern.rb +1 -1
  46. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_evaluated.rb +8 -0
  47. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +1 -1
  48. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +4 -4
  49. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/concern.rb +81 -0
  50. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception/exceptions.rb +38 -0
  51. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_handled_exception.rb +9 -0
  52. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_unhandled_exception/concern.rb +46 -0
  53. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_unhandled_exception.rb +8 -0
  54. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb +2 -0
  55. data/lib/convenient_service/service/plugins/has_j_send_result.rb +84 -0
  56. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +3 -3
  57. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions.rb +0 -2
  58. data/lib/convenient_service/service/plugins.rb +3 -0
  59. data/lib/convenient_service/version.rb +1 -1
  60. data/lib/convenient_service.rb +23 -1
  61. metadata +24 -11
  62. /data/lib/convenient_service/service/plugins/{rescues_result_unhandled_exceptions → can_have_formatted_exceptions}/commands.rb +0 -0
@@ -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
@@ -5,4 +5,4 @@
5
5
  # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
6
6
  ##
7
7
 
8
- require_relative "can_be_completed/concern"
8
+ require_relative "entities/proxy"
@@ -0,0 +1,30 @@
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 Exceptions
13
+ class InlineServiceIsAlreadyDefined < ::ConvenientService::Exception
14
+ ##
15
+ # @param object [Object] Can be any type.
16
+ # @return [void]
17
+ #
18
+ def initialize_with_kwargs(object:)
19
+ message = <<~TEXT
20
+ Definition of already defined inline service can NOT be modified.
21
+ TEXT
22
+
23
+ initialize(message)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
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_inline_services/concern"
9
+ require_relative "can_have_inline_services/entities"
10
+ require_relative "can_have_inline_services/exceptions"
11
+
12
+ # frozen_string_literal: true
13
+
14
+ ##
15
+ # @author Marian Kostyk <mariankostyk13895@gmail.com>
16
+ # @license LGPLv3 <https://www.gnu.org/licenses/lgpl-3.0.html>
17
+ ##
18
+
19
+ module ConvenientService
20
+ module Service
21
+ module Plugins
22
+ module CanHaveInlineServices
23
+ class << self
24
+ ##
25
+ # @api private
26
+ # @param block [Proc, nil]
27
+ # @return [ConvenientService::Service::Plugins::CanHaveInlineServices::Entities::Proxy]
28
+ #
29
+ def proxy(&block)
30
+ Entities::Proxy.new(&block)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -22,6 +22,8 @@ module ConvenientService
22
22
  # @param kwargs [Hash{Symbol => Object}]
23
23
  # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
24
24
  #
25
+ # @see https://userdocs.convenientservice.org/comprehensive_docs/docs/best_practices/declare_in_out_explicitly_on_method_steps.html
26
+ #
25
27
  def step(*args, **kwargs)
26
28
  steps.create(*args, **kwargs)
27
29
  end
@@ -52,11 +52,7 @@ module ConvenientService
52
52
  # Do NOT spend too much time on that again, you have a lot of other tasks to do.
53
53
  #
54
54
  def find_first_not_successful_step_with_side_effects_during_lookup
55
- entity.steps.find do |step|
56
- step.status.unsafe_not_success?
57
- .tap { step.save_outputs_in_organizer! }
58
- .tap { step.mark_as_evaluated! }
59
- end
55
+ entity.steps.find { |step| step.organizer_result.status.unsafe_not_success? }
60
56
  end
61
57
 
62
58
  ##
@@ -24,13 +24,8 @@ module ConvenientService
24
24
  ##
25
25
  # @api public
26
26
  #
27
- # Allows to pass a value to `in` method without its intermediate processing.
28
27
  # @see https://userdocs.convenientservice.org/basics/step_to_result_translation_table
29
- #
30
- # @example `:chat_v2` is passed to `AssertFeatureEnabled` as it is.
31
- # step AssertFeatureEnabled, in: {name: raw(:chat_v2)}
32
- # # that is converted to the following service invocation:
33
- # AssertFeatureEnabled.result(name: :chat_v2)
28
+ # @see https://userdocs.convenientservice.org/comprehensive_docs/docs/the_what/what_is_a_step_raw_input.html
34
29
  #
35
30
  # @param value [Object] Can be any type.
36
31
  # @return [ConvenientService::Support::RawValue]
@@ -27,7 +27,7 @@ module ConvenientService
27
27
  end
28
28
 
29
29
  ##
30
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factries::Base, nil]
30
+ # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factories::Base, nil]
31
31
  #
32
32
  def call
33
33
  return unless factory_class
@@ -59,28 +59,25 @@ module ConvenientService
59
59
  end
60
60
 
61
61
  ##
62
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factries::Base, nil]
62
+ # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factories::Base, nil]
63
63
  #
64
64
  def cast_symbol
65
65
  Entities::Factories::Symbol
66
66
  end
67
67
 
68
68
  ##
69
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factries::Base, nil]
69
+ # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factories::Base, nil]
70
70
  #
71
71
  def cast_string
72
72
  Entities::Factories::String
73
73
  end
74
74
 
75
75
  ##
76
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factries::Base, nil]
76
+ # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factories::Base, nil]
77
77
  #
78
78
  def cast_hash
79
79
  return unless other.keys.one?
80
80
 
81
- ##
82
- # TODO: Add `other.keys.first.is_a?(Integer)` and `other.keys.first == Support::BLOCK` to support args and block via `step`?
83
- #
84
81
  value = other.values.first
85
82
 
86
83
  case value
@@ -96,7 +93,7 @@ module ConvenientService
96
93
  end
97
94
 
98
95
  ##
99
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factries::Base, nil]
96
+ # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Factories::Base, nil]
100
97
  #
101
98
  def cast_method
102
99
  Entities::Factories::Method
@@ -26,7 +26,7 @@ module ConvenientService
26
26
  end
27
27
 
28
28
  def define_output_in_container!(container, index:, method:)
29
- false
29
+ Commands::DefineMethodInContainer.call(method: method, container: container, index: index)
30
30
  end
31
31
 
32
32
  private
@@ -26,7 +26,7 @@ module ConvenientService
26
26
  end
27
27
 
28
28
  def define_output_in_container!(container, index:, method:)
29
- false
29
+ Commands::DefineMethodInContainer.call(method: method, container: container, index: index)
30
30
  end
31
31
 
32
32
  private
@@ -18,7 +18,7 @@ module ConvenientService
18
18
  # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Method::Entities::Key]
19
19
  #
20
20
  def create_key
21
- Entities::Key.new(other)
21
+ Entities::Key.new(other.to_sym)
22
22
  end
23
23
 
24
24
  ##
@@ -25,7 +25,7 @@ module ConvenientService
25
25
  ##
26
26
  # @return [String]
27
27
  #
28
- delegate :to_s, :to_sym, to: :value
28
+ delegate :to_s, to: :value
29
29
 
30
30
  ##
31
31
  # @return [Symbol]
@@ -174,6 +174,19 @@ module ConvenientService
174
174
  @organizer
175
175
  end
176
176
 
177
+ ##
178
+ # @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
179
+ #
180
+ def organizer_result
181
+ original_result = result
182
+
183
+ save_outputs_in_organizer!
184
+
185
+ mark_as_evaluated!
186
+
187
+ original_result
188
+ end
189
+
177
190
  ##
178
191
  # @api public
179
192
  #
@@ -12,7 +12,7 @@ module ConvenientService
12
12
  module Entities
13
13
  class Step
14
14
  module Plugins
15
- module CanBeCompleted
15
+ module CanBeEvaluated
16
16
  module Concern
17
17
  include Support::Concern
18
18
 
@@ -0,0 +1,8 @@
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_be_evaluated/concern"
@@ -7,7 +7,7 @@
7
7
 
8
8
  require_relative "plugins/has_result"
9
9
 
10
- require_relative "plugins/can_be_completed"
10
+ require_relative "plugins/can_be_evaluated"
11
11
  require_relative "plugins/can_be_service_step"
12
12
  require_relative "plugins/can_be_method_step"
13
13
  require_relative "plugins/can_be_used_in_service_aware_enumerables"
@@ -22,8 +22,8 @@ module ConvenientService
22
22
  #
23
23
  # @return [Boolean]
24
24
  #
25
- def from_unhandled_exception?
26
- Utils.to_bool(unhandled_exception)
25
+ def from_exception?
26
+ Utils.to_bool(exception)
27
27
  end
28
28
 
29
29
  ##
@@ -31,8 +31,8 @@ module ConvenientService
31
31
  #
32
32
  # @return [StandardError, nil]
33
33
  #
34
- def unhandled_exception
35
- extra_kwargs[:unhandled_exception]
34
+ def exception
35
+ extra_kwargs[:exceptions]&.values&.first
36
36
  end
37
37
  end
38
38
  end
@@ -0,0 +1,81 @@
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 HasJSendResult
12
+ module Entities
13
+ class Result
14
+ module Plugins
15
+ module CanBeFromHandledException
16
+ module Concern
17
+ include Support::Concern
18
+
19
+ instance_methods do
20
+ ##
21
+ # @api public
22
+ #
23
+ # @return [Boolean]
24
+ #
25
+ def from_handled_exception?
26
+ Utils.to_bool(handled_exception)
27
+ end
28
+
29
+ ##
30
+ # @api public
31
+ #
32
+ # @return [StandardError, nil]
33
+ #
34
+ def handled_exception
35
+ extra_kwargs.dig(:exceptions, :handled)
36
+ end
37
+
38
+ def from_exception(exception, **kwargs)
39
+ ::ConvenientService.raise Exceptions::FromExceptionOnNotErrorResult.new(result: self) unless status.unsafe_error?
40
+ data =
41
+ if Service::Plugins::HasJSendResult.default_error_data == unsafe_data.to_h
42
+ {handled_exception: exception}
43
+ else
44
+ unsafe_data
45
+ end
46
+
47
+ message =
48
+ if Service::Plugins::HasJSendResult.default_error_message == unsafe_message.to_s
49
+ Service::Plugins::CanHaveFormattedExceptions.format_exception(exception, **kwargs)
50
+ else
51
+ unsafe_message
52
+ end
53
+
54
+ code =
55
+ if Service::Plugins::HasJSendResult.default_error_code == unsafe_code.to_sym
56
+ :handled_exception
57
+ else
58
+ unsafe_code
59
+ end
60
+
61
+ copy(
62
+ overrides: {
63
+ kwargs: {
64
+ data: data,
65
+ message: message,
66
+ code: code,
67
+ exceptions: {handled: exception}
68
+ }
69
+ }
70
+ )
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,38 @@
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 HasJSendResult
12
+ module Entities
13
+ class Result
14
+ module Plugins
15
+ module CanBeFromHandledException
16
+ module Exceptions
17
+ class FromExceptionOnNotErrorResult < ::ConvenientService::Exception
18
+ ##
19
+ # @param result [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result]
20
+ # @return [void]
21
+ #
22
+ def initialize_with_kwargs(result:)
23
+ message = <<~TEXT
24
+ `#{result.status}(...).from_exception(exception, ...)` is NOT allowed. Only `error` results can be from exceptions.
25
+ TEXT
26
+
27
+ initialize(message)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -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 "can_be_from_handled_exception/concern"
9
+ require_relative "can_be_from_handled_exception/exceptions"
@@ -0,0 +1,46 @@
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 HasJSendResult
12
+ module Entities
13
+ class Result
14
+ module Plugins
15
+ module CanBeFromUnhandledException
16
+ module Concern
17
+ include Support::Concern
18
+
19
+ instance_methods do
20
+ ##
21
+ # @api public
22
+ #
23
+ # @return [Boolean]
24
+ #
25
+ def from_unhandled_exception?
26
+ Utils.to_bool(unhandled_exception)
27
+ end
28
+
29
+ ##
30
+ # @api public
31
+ #
32
+ # @return [StandardError, nil]
33
+ #
34
+ def unhandled_exception
35
+ extra_kwargs.dig(:exceptions, :unhandled)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
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_be_from_unhandled_exception/concern"
@@ -11,6 +11,8 @@ require_relative "plugins/can_be_strict"
11
11
  require_relative "plugins/can_be_from_fallback"
12
12
  require_relative "plugins/can_have_fallbacks"
13
13
  require_relative "plugins/can_be_from_exception"
14
+ require_relative "plugins/can_be_from_handled_exception"
15
+ require_relative "plugins/can_be_from_unhandled_exception"
14
16
  require_relative "plugins/can_be_own_result"
15
17
  require_relative "plugins/can_be_stubbed_result"
16
18
  require_relative "plugins/can_be_used_in_service_aware_enumerables"