convenient_service 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/lib/convenient_service/commands/is_service.rb +28 -0
  4. data/lib/convenient_service/commands/is_service_class.rb +30 -0
  5. data/lib/convenient_service/commands.rb +4 -0
  6. data/lib/convenient_service/common/plugins.rb +2 -3
  7. data/lib/convenient_service/core/concern/class_methods.rb +3 -0
  8. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +22 -0
  9. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb +1 -1
  10. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creators/observable/entities/event.rb +13 -15
  11. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands/normalize_env.rb +55 -0
  12. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/commands.rb +1 -0
  13. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/chain/concern/instance_methods.rb +3 -3
  14. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middlewares/classic.rb +14 -0
  15. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +22 -0
  16. data/lib/convenient_service/dependencies/built_in.rb +0 -7
  17. data/lib/convenient_service/dependencies/extractions/ds.rb +45 -0
  18. data/lib/convenient_service/dependencies/only_queries.rb +29 -0
  19. data/lib/convenient_service/dependencies/queries/gems/active_model.rb +38 -0
  20. data/lib/convenient_service/dependencies/queries/gems/logger.rb +39 -0
  21. data/lib/convenient_service/dependencies/queries/gems/paint.rb +39 -0
  22. data/lib/convenient_service/dependencies/queries/gems/rspec.rb +60 -0
  23. data/lib/convenient_service/dependencies/queries/ruby.rb +103 -0
  24. data/lib/convenient_service/dependencies/queries/version/null_version.rb +87 -0
  25. data/lib/convenient_service/dependencies/queries/version.rb +87 -0
  26. data/lib/convenient_service/dependencies/queries.rb +536 -0
  27. data/lib/convenient_service/dependencies.rb +2 -438
  28. data/lib/convenient_service/feature/configs/standard.rb +0 -2
  29. data/lib/convenient_service/service/configs/amazing_print_inspect/aliases.rb +7 -0
  30. data/lib/convenient_service/service/configs/amazing_print_inspect.rb +61 -0
  31. data/lib/convenient_service/service/configs/awesome_print_inspect.rb +1 -1
  32. data/lib/convenient_service/service/configs/{minimal.rb → essential.rb} +2 -107
  33. data/lib/convenient_service/service/configs/standard/v1.rb +5 -10
  34. data/lib/convenient_service/service/configs/standard.rb +19 -31
  35. data/lib/convenient_service/service/configs.rb +1 -1
  36. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/and.rb +4 -1
  37. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/empty.rb +4 -4
  38. data/lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb +7 -0
  39. data/lib/convenient_service/service/plugins/can_have_fallbacks/concern.rb +18 -0
  40. data/lib/convenient_service/service/plugins/can_have_fallbacks/exceptions.rb +22 -4
  41. data/lib/convenient_service/service/plugins/can_have_fallbacks/middleware.rb +3 -3
  42. data/lib/convenient_service/service/plugins/can_have_rollbacks/middleware.rb +66 -0
  43. data/lib/convenient_service/service/plugins/can_have_rollbacks.rb +3 -0
  44. data/lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb +7 -0
  45. data/lib/convenient_service/service/plugins/can_have_steps/commands/is_step.rb +34 -0
  46. data/lib/convenient_service/service/plugins/can_have_steps/commands.rb +1 -0
  47. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/concern/instance_methods.rb +22 -14
  48. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_be_method_step/can_be_executed/middleware.rb +1 -15
  49. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/exceptions.rb +53 -0
  50. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/middleware.rb +60 -15
  51. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks.rb +1 -0
  52. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect/concern.rb +46 -0
  53. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_amazing_print_inspect.rb +3 -0
  54. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect/concern.rb +3 -2
  55. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/has_result/middleware.rb +26 -1
  56. data/lib/convenient_service/service/plugins/can_have_steps.rb +41 -0
  57. data/lib/convenient_service/service/plugins/can_have_stubbed_results/commands/fetch_all_services_stubbed_results_cache.rb +2 -2
  58. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/exceptions.rb +53 -0
  59. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments/middleware.rb +108 -0
  60. data/lib/convenient_service/service/plugins/forbids_convenient_service_entities_as_constructor_arguments.rb +4 -0
  61. data/lib/convenient_service/service/plugins/has_amazing_print_inspect/concern.rb +39 -0
  62. data/lib/convenient_service/service/plugins/has_amazing_print_inspect.rb +3 -0
  63. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb +32 -0
  64. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception.rb +3 -0
  65. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_step/concern.rb +7 -0
  66. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect/concern.rb +41 -0
  67. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_amazing_print_inspect.rb +3 -0
  68. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_awesome_print_inspect/concern.rb +2 -2
  69. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/concern/instance_methods.rb +0 -140
  70. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect/concern.rb +46 -0
  71. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_amazing_print_inspect.rb +3 -0
  72. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect/concern.rb +46 -0
  73. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_amazing_print_inspect.rb +3 -0
  74. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect/concern.rb +46 -0
  75. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_amazing_print_inspect.rb +3 -0
  76. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect/concern.rb +46 -0
  77. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_amazing_print_inspect.rb +3 -0
  78. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern/instance_methods.rb +161 -0
  79. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/concern.rb +27 -0
  80. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects/exceptions.rb +34 -0
  81. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/helps_to_learn_similarities_with_common_objects.rb +4 -0
  82. data/lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb +2 -0
  83. data/lib/convenient_service/service/plugins/has_mermaid_flowchart/concern.rb +6 -1
  84. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +1 -0
  85. data/lib/convenient_service/service/plugins.rb +3 -1
  86. data/lib/convenient_service/support/counter.rb +2 -0
  87. data/lib/convenient_service/support/middleware/stack_builder.rb +37 -0
  88. data/lib/convenient_service/support/thread_safe_counter.rb +1 -0
  89. data/lib/convenient_service/support.rb +0 -3
  90. data/lib/convenient_service/utils/object/get_own_method.rb +54 -0
  91. data/lib/convenient_service/utils/object/safe_send.rb +84 -0
  92. data/lib/convenient_service/utils/object.rb +24 -0
  93. data/lib/convenient_service/utils/string/enclose.rb +52 -0
  94. data/lib/convenient_service/utils/string.rb +5 -0
  95. data/lib/convenient_service/version.rb +1 -1
  96. data/lib/convenient_service.rb +62 -0
  97. metadata +149 -16
  98. data/lib/convenient_service/common/plugins/normalizes_env/middleware.rb +0 -31
  99. data/lib/convenient_service/common/plugins/normalizes_env.rb +0 -3
  100. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/can_have_fallbacks/result.rb +0 -3
  101. data/lib/convenient_service/services.rb +0 -4
  102. data/lib/convenient_service/support/gems/active_model.rb +0 -36
  103. data/lib/convenient_service/support/gems/logger.rb +0 -37
  104. data/lib/convenient_service/support/gems/paint.rb +0 -37
  105. data/lib/convenient_service/support/gems/rspec.rb +0 -58
  106. data/lib/convenient_service/support/ruby.rb +0 -53
  107. data/lib/convenient_service/support/version/null_version.rb +0 -85
  108. data/lib/convenient_service/support/version.rb +0 -75
  109. /data/lib/convenient_service/{support → dependencies/queries}/gems.rb +0 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module CanBeFromException
11
+ module Concern
12
+ include Support::Concern
13
+
14
+ instance_methods do
15
+ ##
16
+ # @api public
17
+ #
18
+ # @return [Boolean]
19
+ #
20
+ def from_exception?
21
+ Utils.to_bool(extra_kwargs[:from_exception])
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "can_be_from_exception/concern"
@@ -12,6 +12,13 @@ module ConvenientService
12
12
  include Support::Concern
13
13
 
14
14
  instance_methods do
15
+ ##
16
+ # @return [Boolean]
17
+ #
18
+ def from_step?
19
+ Utils.to_bool(step)
20
+ end
21
+
15
22
  ##
16
23
  # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step, nil]
17
24
  #
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasAmazingPrintInspect
11
+ module Concern
12
+ include Support::Concern
13
+
14
+ instance_methods do
15
+ ##
16
+ # @return [String]
17
+ #
18
+ def inspect
19
+ metadata = {
20
+ ConvenientService: {
21
+ entity: "Result",
22
+ service: service.inspect_values[:name],
23
+ status: status.to_sym
24
+ }
25
+ }
26
+
27
+ metadata[:ConvenientService][:data_keys] = unsafe_data.keys if unsafe_data.keys.any?
28
+ metadata[:ConvenientService][:message] = unsafe_message.to_s unless unsafe_message.empty?
29
+
30
+ metadata.ai
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_amazing_print_inspect/concern"
@@ -24,8 +24,8 @@ module ConvenientService
24
24
  }
25
25
  }
26
26
 
27
- metadata[:data_keys] = unsafe_data.keys if unsafe_data.keys.any?
28
- metadata[:message] = unsafe_message unless unsafe_message.empty?
27
+ metadata[:ConvenientService][:data_keys] = unsafe_data.keys if unsafe_data.keys.any?
28
+ metadata[:ConvenientService][:message] = unsafe_message.to_s unless unsafe_message.empty?
29
29
 
30
30
  metadata.ai
31
31
  end
@@ -165,146 +165,6 @@ module ConvenientService
165
165
  **extra_kwargs
166
166
  )
167
167
  end
168
-
169
- ##
170
- # Returns a boolean representation of `result`.
171
- # `success` may be considered as `true`.
172
- # `failure` may be considered as `false`.
173
- # `error` may be considered as `raise exception`.
174
- #
175
- # @api public
176
- # @return [Boolean]
177
- # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
178
- #
179
- # @note This method is useful for learning purposes, to show similarities with Ruby's booleans. Please, do NOT depend on it in production.
180
- #
181
- # @internal
182
- # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
183
- #
184
- def to_bool
185
- case status.value
186
- when :success
187
- true
188
- when :failure
189
- false
190
- when :error
191
- raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :boolean)
192
- else
193
- raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
194
- end
195
- end
196
-
197
- ##
198
- # Returns a boolean representation of `result`.
199
- # `success` may be considered as `object`.
200
- # `failure` may be considered as `nil` (or null object).
201
- # `error` may be considered as `raise exception`.
202
- #
203
- # @api public
204
- # @return [ConvenientService::Support::Value]
205
- # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
206
- #
207
- # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
208
- #
209
- # @internal
210
- # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
211
- #
212
- def to_object
213
- case status.value
214
- when :success
215
- Support::Value.new("object")
216
- when :failure
217
- nil
218
- when :error
219
- raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :object)
220
- else
221
- raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
222
- end
223
- end
224
-
225
- ##
226
- # Returns an array representation of `result`.
227
- # `success` may be considered as array with items.
228
- # `failure` may be considered as empty array.
229
- # `error` may be considered as `raise exception`.
230
- #
231
- # @api public
232
- # @return [Array<ConvenientService::Support::Value>]
233
- # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
234
- #
235
- # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
236
- #
237
- # @internal
238
- # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
239
- #
240
- def to_a
241
- case status.value
242
- when :success
243
- [Support::Value.new("item")]
244
- when :failure
245
- []
246
- when :error
247
- raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :array)
248
- else
249
- raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
250
- end
251
- end
252
-
253
- ##
254
- # Returns a hash representation of `result`.
255
- # `success` may be considered as hash with items.
256
- # `failure` may be considered as empty hash.
257
- # `error` may be considered as `raise exception`.
258
- #
259
- # @api public
260
- # @return [Hash{ConvenientService::Support::Value => ConvenientService::Support::Value}]
261
- # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
262
- #
263
- # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
264
- #
265
- # @internal
266
- # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
267
- #
268
- def to_h
269
- case status.value
270
- when :success
271
- {Support::Value.new("key") => Support::Value.new("value")}
272
- when :failure
273
- {}
274
- when :error
275
- raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :hash)
276
- else
277
- raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
278
- end
279
- end
280
-
281
- ##
282
- # Returns a string representation of `result`.
283
- # `success` may be considered as string with content.
284
- # `failure` may be considered as empty string.
285
- # `error` may be considered as `raise exception`.
286
- #
287
- # @api public
288
- # @return [String]
289
- # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
290
- #
291
- # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
292
- #
293
- # @internal
294
- # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
295
- #
296
- def to_s
297
- case status.value
298
- when :success
299
- "string"
300
- when :failure
301
- ""
302
- when :error
303
- raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :string)
304
- else
305
- raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
306
- end
307
- end
308
168
  end
309
169
  end
310
170
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Code
13
+ module Plugins
14
+ module HasAmazingPrintInspect
15
+ module Concern
16
+ include Support::Concern
17
+
18
+ instance_methods do
19
+ ##
20
+ # @return [String]
21
+ #
22
+ def inspect
23
+ metadata = {
24
+ ConvenientService: {
25
+ entity: "Code",
26
+ result: result.class.name,
27
+ value: to_sym
28
+ }
29
+ }
30
+
31
+ metadata.ai
32
+ end
33
+ end
34
+ end
35
+ end
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,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Data
13
+ module Plugins
14
+ module HasAmazingPrintInspect
15
+ module Concern
16
+ include Support::Concern
17
+
18
+ instance_methods do
19
+ ##
20
+ # @return [String]
21
+ #
22
+ def inspect
23
+ metadata = {
24
+ ConvenientService: {
25
+ entity: "Data",
26
+ result: result.class.name,
27
+ values: to_h
28
+ }
29
+ }
30
+
31
+ metadata.ai
32
+ end
33
+ end
34
+ end
35
+ end
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,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Message
13
+ module Plugins
14
+ module HasAmazingPrintInspect
15
+ module Concern
16
+ include Support::Concern
17
+
18
+ instance_methods do
19
+ ##
20
+ # @return [String]
21
+ #
22
+ def inspect
23
+ metadata = {
24
+ ConvenientService: {
25
+ entity: "Message",
26
+ result: result.class.name,
27
+ text: to_s
28
+ }
29
+ }
30
+
31
+ metadata.ai
32
+ end
33
+ end
34
+ end
35
+ end
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,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Status
13
+ module Plugins
14
+ module HasAmazingPrintInspect
15
+ module Concern
16
+ include Support::Concern
17
+
18
+ instance_methods do
19
+ ##
20
+ # @return [String]
21
+ #
22
+ def inspect
23
+ metadata = {
24
+ ConvenientService: {
25
+ entity: "Status",
26
+ result: result.class.name,
27
+ type: to_sym
28
+ }
29
+ }
30
+
31
+ metadata.ai
32
+ end
33
+ end
34
+ end
35
+ end
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,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasJSendResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HelpsToLearnSimilaritiesWithCommonObjects
11
+ module Concern
12
+ module InstanceMethods
13
+ ##
14
+ # Returns a boolean representation of `result`.
15
+ # `success` may be considered as `true`.
16
+ # `failure` may be considered as `false`.
17
+ # `error` may be considered as `raise exception`.
18
+ #
19
+ # @api public
20
+ # @return [Boolean]
21
+ # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
22
+ #
23
+ # @note This method is useful for learning purposes, to show similarities with Ruby's booleans. Please, do NOT depend on it in production.
24
+ #
25
+ # @internal
26
+ # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
27
+ #
28
+ def to_bool
29
+ case status.value
30
+ when :success
31
+ true
32
+ when :failure
33
+ false
34
+ when :error
35
+ raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :boolean)
36
+ else
37
+ raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
38
+ end
39
+ end
40
+
41
+ ##
42
+ # Returns a boolean representation of `result`.
43
+ # `success` may be considered as `object`.
44
+ # `failure` may be considered as `nil` (or null object).
45
+ # `error` may be considered as `raise exception`.
46
+ #
47
+ # @api public
48
+ # @return [ConvenientService::Support::Value]
49
+ # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
50
+ #
51
+ # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
52
+ #
53
+ # @internal
54
+ # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
55
+ #
56
+ def to_object
57
+ case status.value
58
+ when :success
59
+ Support::Value.new("object")
60
+ when :failure
61
+ nil
62
+ when :error
63
+ raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :object)
64
+ else
65
+ raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Returns an array representation of `result`.
71
+ # `success` may be considered as array with items.
72
+ # `failure` may be considered as empty array.
73
+ # `error` may be considered as `raise exception`.
74
+ #
75
+ # @api public
76
+ # @return [Array<ConvenientService::Support::Value>]
77
+ # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
78
+ #
79
+ # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
80
+ #
81
+ # @internal
82
+ # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
83
+ #
84
+ def to_a
85
+ case status.value
86
+ when :success
87
+ [Support::Value.new("item")]
88
+ when :failure
89
+ []
90
+ when :error
91
+ raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :array)
92
+ else
93
+ raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
94
+ end
95
+ end
96
+
97
+ ##
98
+ # Returns a hash representation of `result`.
99
+ # `success` may be considered as hash with items.
100
+ # `failure` may be considered as empty hash.
101
+ # `error` may be considered as `raise exception`.
102
+ #
103
+ # @api public
104
+ # @return [Hash{ConvenientService::Support::Value => ConvenientService::Support::Value}]
105
+ # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
106
+ #
107
+ # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
108
+ #
109
+ # @internal
110
+ # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
111
+ #
112
+ def to_h
113
+ case status.value
114
+ when :success
115
+ {Support::Value.new("key") => Support::Value.new("value")}
116
+ when :failure
117
+ {}
118
+ when :error
119
+ raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :hash)
120
+ else
121
+ raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
122
+ end
123
+ end
124
+
125
+ ##
126
+ # Returns a string representation of `result`.
127
+ # `success` may be considered as string with content.
128
+ # `failure` may be considered as empty string.
129
+ # `error` may be considered as `raise exception`.
130
+ #
131
+ # @api public
132
+ # @return [String]
133
+ # @raise [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status::Exceptions::ErrorHasNoOtherTypeRepresentation]
134
+ #
135
+ # @note This method is useful for learning purposes, to show similarities with Ruby's objects. Please, do NOT depend on it in production.
136
+ #
137
+ # @internal
138
+ # NOTE: When `value` is NOT `:success`, `:failure` or `:error`, then something fatal has happened.
139
+ #
140
+ def to_s
141
+ case status.value
142
+ when :success
143
+ "string"
144
+ when :failure
145
+ ""
146
+ when :error
147
+ raise ::ConvenientService.raise Exceptions::ErrorHasNoOtherTypeRepresentation.new(type: :string)
148
+ else
149
+ raise ::ConvenientService.raise Support::NeverReachHere.new(extra_message: "Unknown result status `#{status.value}`.")
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "concern/instance_methods"
4
+
5
+ module ConvenientService
6
+ module Service
7
+ module Plugins
8
+ module HasJSendResult
9
+ module Entities
10
+ class Result
11
+ module Plugins
12
+ module HelpsToLearnSimilaritiesWithCommonObjects
13
+ module Concern
14
+ include Support::Concern
15
+
16
+ included do |result_class|
17
+ result_class.include InstanceMethods
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end