convenient_service 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/.dev/.tmuxinator.yml +2 -1
  3. data/.github/workflows/ci.yml +21 -1
  4. data/CHANGELOG.md +67 -0
  5. data/Gemfile +6 -0
  6. data/README.md +4 -2
  7. data/Taskfile.yml +94 -0
  8. data/convenient_service.gemspec +40 -2
  9. data/docker/2.7/Dockerfile +3 -3
  10. data/docker/3.0/Dockerfile +2 -2
  11. data/docker/3.1/Dockerfile +2 -2
  12. data/docker/3.2/Dockerfile +73 -0
  13. data/docker/jruby-9.4/Dockerfile +88 -0
  14. data/docker/truffleruby-22.3/Dockerfile +91 -0
  15. data/lib/convenient_service/common/plugins/aliases.rb +0 -1
  16. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb +12 -8
  17. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +3 -3
  18. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/errors.rb +2 -2
  19. data/lib/convenient_service/common/plugins/has_around_callbacks/errors.rb +1 -1
  20. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +7 -7
  21. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/aliases.rb +7 -0
  22. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb +2 -0
  23. data/lib/convenient_service/configs/minimal.rb +19 -10
  24. data/lib/convenient_service/core/class_methods.rb +24 -9
  25. data/lib/convenient_service/core/constants.rb +36 -0
  26. data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +69 -0
  27. data/lib/convenient_service/core/entities/config/commands.rb +3 -0
  28. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +10 -10
  29. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +3 -3
  30. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +18 -1
  31. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creator.rb +62 -0
  32. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +12 -12
  33. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +1 -0
  34. data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +1 -1
  35. data/lib/convenient_service/core/entities/config/errors.rb +38 -1
  36. data/lib/convenient_service/core/entities/config.rb +14 -4
  37. data/lib/convenient_service/core/instance_methods.rb +6 -4
  38. data/lib/convenient_service/core.rb +1 -0
  39. data/lib/convenient_service/dependencies/built_in.rb +7 -0
  40. data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +18 -2
  41. data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +4 -0
  42. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +7 -1
  43. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +7 -1
  44. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +15 -1
  45. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -1
  46. data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +3 -2
  47. data/lib/convenient_service/dependencies.rb +16 -15
  48. data/lib/convenient_service/examples/dry/gemfile.rb +4 -4
  49. data/lib/convenient_service/examples/rails/gemfile.rb +4 -4
  50. data/lib/convenient_service/examples/standard/cowsay.rb +4 -4
  51. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +1 -1
  52. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +1 -1
  53. data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +0 -9
  54. data/lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb +0 -10
  55. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +0 -10
  56. data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +0 -10
  57. data/lib/convenient_service/examples/standard/gemfile/services/parse_content.rb +0 -10
  58. data/lib/convenient_service/examples/standard/gemfile/services/read_file_content.rb +0 -10
  59. data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +0 -10
  60. data/lib/convenient_service/examples/standard/gemfile.rb +4 -4
  61. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +0 -10
  62. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +0 -10
  63. data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +0 -10
  64. data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +0 -10
  65. data/lib/convenient_service/examples/standard/request_params.rb +4 -4
  66. data/lib/convenient_service/feature.rb +12 -0
  67. data/lib/convenient_service/logger.rb +6 -5
  68. data/lib/convenient_service/rspec/helpers/custom/in_threads.rb +74 -0
  69. data/lib/convenient_service/rspec/helpers/custom/stub_service/constants.rb +20 -0
  70. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +4 -4
  71. data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +1 -0
  72. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +3 -3
  73. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +1 -1
  74. data/lib/convenient_service/rspec/helpers/custom.rb +1 -0
  75. data/lib/convenient_service/rspec/helpers/in_threads.rb +13 -0
  76. data/lib/convenient_service/rspec/helpers.rb +2 -0
  77. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +3 -3
  78. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +3 -3
  79. data/lib/convenient_service/rspec/matchers/custom/export.rb +82 -0
  80. data/lib/convenient_service/rspec/matchers/custom/results/base/constants.rb +22 -0
  81. data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +1 -1
  82. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +2 -1
  83. data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
  84. data/lib/convenient_service/rspec/matchers/export.rb +13 -0
  85. data/lib/convenient_service/rspec/matchers.rb +2 -0
  86. data/lib/convenient_service/service/plugins/aliases.rb +0 -2
  87. data/lib/convenient_service/service/plugins/can_have_method_steps/middleware.rb +2 -2
  88. data/lib/convenient_service/service/plugins/can_have_result_step/middleware.rb +2 -2
  89. data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +2 -2
  90. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method.rb +46 -11
  91. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_direction.rb +29 -2
  92. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +113 -0
  93. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands.rb +1 -3
  94. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/base.rb +62 -0
  95. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/base.rb +35 -0
  96. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/proc_value.rb +42 -0
  97. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/raw_value.rb +42 -0
  98. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/reassignment_value.rb +42 -0
  99. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/string_value.rb +42 -0
  100. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/symbol_value.rb +42 -0
  101. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash.rb +8 -0
  102. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/method.rb +40 -0
  103. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/reassignment.rb +40 -0
  104. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +40 -0
  105. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/symbol.rb +40 -0
  106. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories.rb +8 -0
  107. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities.rb +1 -0
  108. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/errors.rb +7 -7
  109. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/errors.rb +12 -8
  110. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/aliases.rb +7 -0
  111. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +2 -0
  112. data/lib/convenient_service/service/plugins/can_have_steps/entities/step_collection.rb +37 -8
  113. data/lib/convenient_service/service/plugins/can_have_stubbed_result/concern.rb +19 -11
  114. data/lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb +3 -3
  115. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +3 -3
  116. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/aliases.rb +7 -0
  117. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +12 -5
  118. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/concern/class_methods.rb → can_have_parent_result/constants.rb} +3 -4
  119. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +1 -0
  120. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb → has_j_send_status_and_attributes/commands/cast_j_send_attributes.rb} +1 -1
  121. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_code_class.rb +49 -0
  122. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_data_class.rb +49 -0
  123. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_message_class.rb +49 -0
  124. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_status_class.rb +49 -0
  125. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands.rb +7 -0
  126. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/concern/class_methods.rb +69 -0
  127. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern/instance_methods.rb +9 -9
  128. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern.rb +1 -1
  129. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/class_methods.rb +2 -2
  130. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/instance_methods.rb +3 -3
  131. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern.rb +1 -1
  132. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code.rb +1 -1
  133. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/class_methods.rb +38 -0
  134. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb +94 -0
  135. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern.rb +36 -0
  136. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data.rb +25 -0
  137. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/class_methods.rb +40 -0
  138. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/instance_methods.rb +58 -0
  139. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern.rb +36 -0
  140. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message.rb +25 -0
  141. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/class_methods.rb +40 -0
  142. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +115 -0
  143. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern.rb +36 -0
  144. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status.rb +25 -0
  145. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/errors.rb +6 -2
  146. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/middleware.rb +4 -4
  147. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/structs/jsend_attributes.rb → has_j_send_status_and_attributes/structs/j_send_attributes.rb} +1 -1
  148. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/structs.rb +3 -0
  149. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes.rb +8 -0
  150. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +3 -3
  151. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +1 -1
  152. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +3 -1
  153. data/lib/convenient_service/service/plugins/has_result/errors.rb +2 -2
  154. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +16 -0
  155. data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +1 -1
  156. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +1 -1
  157. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +11 -10
  158. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +14 -7
  159. data/lib/convenient_service/services/run_own_method_in_organizer.rb +1 -1
  160. data/lib/convenient_service/support/abstract_method/errors.rb +1 -1
  161. data/lib/convenient_service/support/arguments.rb +3 -3
  162. data/lib/convenient_service/support/cache/key.rb +3 -3
  163. data/lib/convenient_service/support/cache.rb +1 -1
  164. data/lib/convenient_service/support/castable/errors.rb +2 -2
  165. data/lib/convenient_service/support/counter.rb +212 -0
  166. data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +33 -0
  167. data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +58 -0
  168. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +4 -3
  169. data/lib/convenient_service/support/dependency_container/commands/define_entry.rb +49 -0
  170. data/lib/convenient_service/support/dependency_container/commands.rb +3 -0
  171. data/lib/convenient_service/support/dependency_container/container.rb +23 -0
  172. data/lib/convenient_service/support/dependency_container/entry.rb +22 -0
  173. data/lib/convenient_service/support/dependency_container/errors.rb +5 -5
  174. data/lib/convenient_service/support/dependency_container/import.rb +3 -3
  175. data/lib/convenient_service/support/dependency_container.rb +3 -0
  176. data/lib/convenient_service/support/finite_loop.rb +37 -2
  177. data/lib/convenient_service/support/middleware/stack_builder.rb +1 -1
  178. data/lib/convenient_service/support/not_passed.rb +4 -3
  179. data/lib/convenient_service/support/ruby.rb +31 -0
  180. data/lib/convenient_service/support/safe_method.rb +65 -0
  181. data/lib/convenient_service/support/thread_safe_counter.rb +119 -0
  182. data/lib/convenient_service/support/undefined.rb +4 -3
  183. data/lib/convenient_service/support/unique_value.rb +69 -0
  184. data/lib/convenient_service/support.rb +4 -0
  185. data/lib/convenient_service/utils/array/errors.rb +1 -1
  186. data/lib/convenient_service/utils/array/find_last.rb +1 -1
  187. data/lib/convenient_service/utils/array/find_yield.rb +1 -1
  188. data/lib/convenient_service/utils/object/resolve_class.rb +56 -0
  189. data/lib/convenient_service/utils/object.rb +9 -0
  190. data/lib/convenient_service/version.rb +1 -1
  191. data/lib/convenient_service.rb +6 -0
  192. metadata +75 -34
  193. data/lib/convenient_service/factories/arguments.rb +0 -43
  194. data/lib/convenient_service/factories/results.rb +0 -214
  195. data/lib/convenient_service/factories/services.rb +0 -229
  196. data/lib/convenient_service/factories/step/instance.rb +0 -42
  197. data/lib/convenient_service/factories/step.rb +0 -3
  198. data/lib/convenient_service/factories/steps.rb +0 -126
  199. data/lib/convenient_service/factories.rb +0 -22
  200. data/lib/convenient_service/factory.rb +0 -21
  201. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_caller.rb +0 -74
  202. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_key.rb +0 -78
  203. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_name.rb +0 -78
  204. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +0 -3
  205. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +0 -32
  206. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +0 -74
  207. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +0 -34
  208. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +0 -45
  209. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +0 -34
  210. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +0 -77
  211. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +0 -3
  212. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +0 -8
  213. /data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities.rb +0 -0
@@ -1,229 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
- #
6
- module ConvenientService
7
- module Factories
8
- module Services
9
- ##
10
- # @return [Class]
11
- #
12
- # @example Default.
13
- # class Service # `service` is class.
14
- # include ConvenientService::Standard::Config
15
- #
16
- # def result
17
- # success
18
- # end
19
- # end
20
- #
21
- def create_service_with_success_result
22
- ::Class.new do
23
- include ::ConvenientService::Configs::Standard
24
-
25
- ##
26
- # IMPORTANT:
27
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
28
- # - It will be reenabled after the introduction of thread-safety specs.
29
- # - Do not use it in production yet.
30
- #
31
- middlewares :step, scope: :class do
32
- use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
33
- end
34
-
35
- def result
36
- success
37
- end
38
- end
39
- end
40
-
41
- ##
42
- # @return [Class]
43
- #
44
- # @example Default.
45
- # class Service # `service` is class.
46
- # include ConvenientService::Standard::Config
47
- #
48
- # def result
49
- # error("foo")
50
- # end
51
- # end
52
- #
53
- def create_service_with_not_success_result
54
- create_service_with_error_result
55
- end
56
-
57
- ##
58
- # @return [Class]
59
- #
60
- # @example Default.
61
- # class Service # `service` is class.
62
- # include ConvenientService::Standard::Config
63
- #
64
- # def result
65
- # failure(foo: "bar")
66
- # end
67
- # end
68
- #
69
- def create_service_with_failure_result
70
- ::Class.new do
71
- include ::ConvenientService::Configs::Standard
72
-
73
- ##
74
- # IMPORTANT:
75
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
76
- # - It will be reenabled after the introduction of thread-safety specs.
77
- # - Do not use it in production yet.
78
- #
79
- middlewares :step, scope: :class do
80
- use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
81
- end
82
-
83
- def result
84
- failure(data)
85
- end
86
-
87
- private
88
-
89
- def data
90
- @data ||= {::Faker::Lorem.word => ::Faker::Lorem.sentence}
91
- end
92
- end
93
- end
94
-
95
- ##
96
- # @return [Class]
97
- #
98
- # @example Default.
99
- # class Service # `service` is class.
100
- # include ConvenientService::Standard::Config
101
- #
102
- # def result
103
- # error("foo")
104
- # end
105
- # end
106
- #
107
- def create_service_with_error_result
108
- ::Class.new do
109
- include ::ConvenientService::Configs::Standard
110
-
111
- ##
112
- # IMPORTANT:
113
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
114
- # - It will be reenabled after the introduction of thread-safety specs.
115
- # - Do not use it in production yet.
116
- #
117
- middlewares :step, scope: :class do
118
- use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
119
- end
120
-
121
- def result
122
- error(message)
123
- end
124
-
125
- private
126
-
127
- def message
128
- @message ||= ::Faker::Lorem.sentence
129
- end
130
- end
131
- end
132
-
133
- ##
134
- # @return [Class]
135
- #
136
- # @example Default.
137
- # class Service # `service` is class.
138
- # include ConvenientService::Standard::Config
139
- #
140
- # def result
141
- # success
142
- # end
143
- # end
144
- #
145
- def create_service(...)
146
- create_service_class(...)
147
- end
148
-
149
- ##
150
- # @param steps [<Class, Symbol>]
151
- # @return [Class]
152
- #
153
- # @example Default.
154
- # class Service # `service` is class.
155
- # include ConvenientService::Standard::Config
156
- #
157
- # def result
158
- # success
159
- # end
160
- # end
161
- #
162
- # @example One step.
163
- # class Service # `service` is class.
164
- # include ConvenientService::Standard::Config
165
- #
166
- # step Step # `steps.first` is `args.first`.
167
- # end
168
- #
169
- # @example One method step.
170
- # class Service # `service` is class.
171
- # include ConvenientService::Standard::Config
172
- #
173
- # step :validate # `steps.first` is `args.first`.
174
- #
175
- # def validate
176
- # success
177
- # end
178
- # end
179
- #
180
- # @example Multiple steps.
181
- # class Service # `service` is class.
182
- # include ConvenientService::Standard::Config
183
- #
184
- # step Step # `steps[0]` is `args.first`.
185
- # step OtherStep # `steps[1]` is `args.first`.
186
- # step :result # `steps[2]` is `args.first`.
187
- #
188
- # def result
189
- # success
190
- # end
191
- # end
192
- #
193
- def create_service_class(steps: [])
194
- ::Class.new.tap do |klass|
195
- klass.class_exec(steps: steps) do
196
- include ::ConvenientService::Configs::Standard
197
-
198
- ##
199
- # IMPORTANT:
200
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
201
- # - It will be reenabled after the introduction of thread-safety specs.
202
- # - Do not use it in production yet.
203
- #
204
- middlewares :step, scope: :class do
205
- use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
206
- end
207
-
208
- steps.each do |step_name|
209
- case step_name
210
- when ::Class
211
- step step_name
212
- when ::Symbol
213
- step step_name
214
-
215
- define_method(step_name) { success }
216
- end
217
- end
218
-
219
- if steps.none?
220
- def result
221
- success
222
- end
223
- end
224
- end
225
- end
226
- end
227
- end
228
- end
229
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
- #
6
- module ConvenientService
7
- module Factories
8
- module Step
9
- module Instance
10
- ##
11
- # @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
12
- #
13
- def create_step_instance
14
- service_class =
15
- ::Class.new do
16
- include ::ConvenientService::Configs::Standard
17
-
18
- ##
19
- # IMPORTANT:
20
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
21
- # - It will be reenabled after the introduction of thread-safety specs.
22
- # - Do not use it in production yet.
23
- #
24
- middlewares :step, scope: :class do
25
- use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
26
- end
27
-
28
- step :result
29
-
30
- def result
31
- success
32
- end
33
- end
34
-
35
- service_instance = service_class.new
36
-
37
- service_instance.steps.first
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "step/instance"
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
- #
6
- module ConvenientService
7
- module Factories
8
- module Steps
9
- ##
10
- # @return [Class]
11
- #
12
- # @example Default.
13
- #
14
- # class Step
15
- # include ConvenienService::Standard::Config
16
- # end
17
- #
18
- # class Service
19
- # include ConvenienService::Standard::Config
20
- # # ...
21
- # step Step # `step` is `args.first`
22
- # # ...
23
- # end
24
- #
25
- def create_step(...)
26
- create_service_step_class(...)
27
- end
28
-
29
- ##
30
- # @return [Integer]
31
- #
32
- # @example Default.
33
- #
34
- # class Service
35
- # include ConvenienService::Standard::Config
36
- # # ...
37
- # step 42 # `step` is `args.first`
38
- # # ...
39
- # end
40
- #
41
- def create_invalid_step(...)
42
- 42
43
- end
44
-
45
- ##
46
- # @return [Class]
47
- #
48
- # @example Default.
49
- #
50
- # class Step
51
- # include ConvenienService::Standard::Config
52
- # end
53
- #
54
- # class Service
55
- # include ConvenienService::Standard::Config
56
- # # ...
57
- # step Step # `step` is `args.first`
58
- # # ...
59
- # end
60
- #
61
- def create_service_step(...)
62
- create_service_step_class(...)
63
- end
64
-
65
- ##
66
- # @return [Symbol]
67
- #
68
- # @example Default.
69
- #
70
- # class Step
71
- # include ConvenienService::Standard::Config
72
- # end
73
- #
74
- # class Service
75
- # include ConvenienService::Standard::Config
76
- # # ...
77
- # step :validate # `step` is `args.first`
78
- # # ...
79
- # end
80
- #
81
- def create_method_step
82
- ::Faker::Verb.unique.base.to_sym
83
- end
84
-
85
- ##
86
- # @return [Symbol]
87
- #
88
- # @example Default.
89
- #
90
- # class Step
91
- # include ConvenienService::Standard::Config
92
- # end
93
- #
94
- # class Service
95
- # include ConvenienService::Standard::Config
96
- # # ...
97
- # step :result # `step` is `args.first`
98
- # # ...
99
- # end
100
- #
101
- def create_result_method_step
102
- :result
103
- end
104
-
105
- ##
106
- # @return [Class]
107
- #
108
- # @example Default.
109
- #
110
- # class Step
111
- # include ConvenienService::Standard::Config
112
- # end
113
- #
114
- # class Service
115
- # include ConvenienService::Standard::Config
116
- # # ...
117
- # step Step # `step` is `args.first`
118
- # # ...
119
- # end
120
- #
121
- def create_service_step_class
122
- create_service_class
123
- end
124
- end
125
- end
126
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "factories/arguments"
4
- require_relative "factories/services"
5
- require_relative "factories/results"
6
- require_relative "factories/steps"
7
-
8
- require_relative "factories/step"
9
-
10
- ##
11
- # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
12
- #
13
- module ConvenientService
14
- module Factories
15
- extend Arguments
16
- extend Services
17
- extend Results
18
- extend Steps
19
-
20
- extend Step::Instance
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "factories"
4
-
5
- ##
6
- # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
7
- #
8
- module ConvenientService
9
- module Factory
10
- class << self
11
- ##
12
- # @param method [String, Symbol]
13
- # @param kwargs [Hash]
14
- # @return [Object] Can be any type.
15
- #
16
- def create(method, **kwargs)
17
- Factories.public_send("create_#{method}", **kwargs)
18
- end
19
- end
20
- end
21
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Service
5
- module Plugins
6
- module CanHaveSteps
7
- module Entities
8
- class Method
9
- module Commands
10
- ##
11
- # TODO: Abstract factory.
12
- #
13
- class CastMethodCaller < Support::Command
14
- attr_reader :other, :options
15
-
16
- def initialize(other:, options:)
17
- @other = other
18
- @options = options
19
- end
20
-
21
- def call
22
- case other
23
- when ::Symbol then cast_symbol
24
- when ::String then cast_string
25
- when ::Hash then cast_hash
26
- when Entities::Values::Reassignment then cast_reassignment
27
- when Method then cast_method
28
- end
29
- end
30
-
31
- private
32
-
33
- def cast_symbol
34
- Entities::Callers::Usual.new(other)
35
- end
36
-
37
- def cast_string
38
- Entities::Callers::Usual.new(other)
39
- end
40
-
41
- def cast_reassignment
42
- Entities::Callers::Reassignment.new(other)
43
- end
44
-
45
- def cast_hash
46
- return unless other.keys.one?
47
-
48
- value = other.values.first
49
-
50
- case value
51
- when ::Symbol
52
- Entities::Callers::Alias.new(value)
53
- when ::String
54
- Entities::Callers::Alias.new(value)
55
- when ::Proc
56
- Entities::Callers::Proc.new(value)
57
- when Support::RawValue
58
- Entities::Callers::Raw.new(value)
59
- when Entities::Values::Reassignment
60
- Entities::Callers::Reassignment.new(value)
61
- end
62
- end
63
-
64
- def cast_method
65
- other.caller.copy
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Service
5
- module Plugins
6
- module CanHaveSteps
7
- module Entities
8
- class Method
9
- module Commands
10
- ##
11
- # TODO: Abstract factory.
12
- #
13
- class CastMethodKey < Support::Command
14
- attr_reader :other, :options
15
-
16
- def initialize(other:, options:)
17
- @other = other
18
- @options = options
19
- end
20
-
21
- def call
22
- ##
23
- # TODO: Use pattern matcher when Ruby 2.7.
24
- #
25
- case other
26
- when ::Symbol then cast_symbol
27
- when ::String then cast_string
28
- when ::Hash then cast_hash
29
- when Entities::Values::Reassignment then cast_reassignment
30
- when Method then cast_method
31
- end
32
- end
33
-
34
- private
35
-
36
- def cast_symbol
37
- Entities::Key.new(other)
38
- end
39
-
40
- def cast_string
41
- Entities::Key.new(other)
42
- end
43
-
44
- def cast_reassignment
45
- Entities::Key.new(other.to_sym)
46
- end
47
-
48
- def cast_hash
49
- return unless other.keys.one?
50
-
51
- key = other.keys.first
52
- value = other.values.first
53
-
54
- case value
55
- when ::Symbol
56
- Entities::Key.new(key)
57
- when ::String
58
- Entities::Key.new(key)
59
- when ::Proc
60
- Entities::Key.new(key)
61
- when Support::RawValue
62
- Entities::Key.new(key)
63
- when Entities::Values::Reassignment
64
- Entities::Key.new(key)
65
- end
66
- end
67
-
68
- def cast_method
69
- other.key.copy
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConvenientService
4
- module Service
5
- module Plugins
6
- module CanHaveSteps
7
- module Entities
8
- class Method
9
- module Commands
10
- #
11
- # TODO: Abstract factory.
12
- #
13
- class CastMethodName < Support::Command
14
- attr_reader :other, :options
15
-
16
- def initialize(other:, options:)
17
- @other = other
18
- @options = options
19
- end
20
-
21
- def call
22
- ##
23
- # TODO: Use pattern matcher when Ruby 2.7.
24
- #
25
- case other
26
- when ::Symbol then cast_symbol
27
- when ::String then cast_string
28
- when ::Hash then cast_hash
29
- when Entities::Values::Reassignment then cast_reassignment
30
- when Method then cast_method
31
- end
32
- end
33
-
34
- private
35
-
36
- def cast_symbol
37
- Entities::Name.new(other)
38
- end
39
-
40
- def cast_string
41
- Entities::Name.new(other)
42
- end
43
-
44
- def cast_reassignment
45
- Entities::Name.new(other.to_sym)
46
- end
47
-
48
- def cast_hash
49
- return unless other.keys.one?
50
-
51
- key = other.keys.first
52
- value = other.values.first
53
-
54
- case value
55
- when ::Symbol
56
- Entities::Name.new(value)
57
- when ::String
58
- Entities::Name.new(value)
59
- when ::Proc
60
- Entities::Name.new(key)
61
- when Support::RawValue
62
- Entities::Name.new(key)
63
- when Entities::Values::Reassignment
64
- Entities::Name.new(value.to_sym)
65
- end
66
- end
67
-
68
- def cast_method
69
- other.name.copy
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "commands/cast_jsend_attributes"