convenient_service 0.10.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) 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 +90 -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 +23 -4
  24. data/lib/convenient_service/configs/standard.rb +0 -4
  25. data/lib/convenient_service/core/class_methods.rb +24 -9
  26. data/lib/convenient_service/core/constants.rb +36 -0
  27. data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +69 -0
  28. data/lib/convenient_service/core/entities/config/commands.rb +3 -0
  29. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +10 -10
  30. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +3 -3
  31. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +18 -1
  32. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creator.rb +62 -0
  33. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +12 -12
  34. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +1 -0
  35. data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +1 -1
  36. data/lib/convenient_service/core/entities/config/errors.rb +38 -1
  37. data/lib/convenient_service/core/entities/config.rb +14 -4
  38. data/lib/convenient_service/core/instance_methods.rb +6 -4
  39. data/lib/convenient_service/core.rb +1 -0
  40. data/lib/convenient_service/dependencies/built_in.rb +7 -0
  41. data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +18 -2
  42. data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +4 -0
  43. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +7 -1
  44. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +7 -1
  45. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +15 -1
  46. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -1
  47. data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +3 -2
  48. data/lib/convenient_service/dependencies.rb +16 -15
  49. data/lib/convenient_service/examples/dry/gemfile.rb +4 -4
  50. data/lib/convenient_service/examples/rails/gemfile.rb +4 -4
  51. data/lib/convenient_service/examples/standard/cowsay.rb +4 -4
  52. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +1 -1
  53. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +1 -1
  54. data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +0 -9
  55. data/lib/convenient_service/examples/standard/gemfile.rb +4 -4
  56. data/lib/convenient_service/examples/standard/request_params.rb +4 -4
  57. data/lib/convenient_service/feature.rb +12 -0
  58. data/lib/convenient_service/logger.rb +6 -5
  59. data/lib/convenient_service/rspec/helpers/custom/in_threads.rb +74 -0
  60. data/lib/convenient_service/rspec/helpers/custom/stub_service/constants.rb +20 -0
  61. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +4 -4
  62. data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +1 -0
  63. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +3 -3
  64. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +1 -1
  65. data/lib/convenient_service/rspec/helpers/custom.rb +1 -0
  66. data/lib/convenient_service/rspec/helpers/in_threads.rb +13 -0
  67. data/lib/convenient_service/rspec/helpers.rb +2 -0
  68. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +3 -3
  69. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +3 -3
  70. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher.rb +2 -2
  71. data/lib/convenient_service/rspec/matchers/custom/export.rb +82 -0
  72. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_method_step.rb +4 -4
  73. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_result_method_step.rb +4 -4
  74. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_service_step.rb +1 -1
  75. data/lib/convenient_service/rspec/matchers/custom/results/base/constants.rb +22 -0
  76. data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +1 -1
  77. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +2 -1
  78. data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
  79. data/lib/convenient_service/rspec/matchers/export.rb +13 -0
  80. data/lib/convenient_service/rspec/matchers.rb +2 -0
  81. data/lib/convenient_service/service/plugins/aliases.rb +0 -2
  82. data/lib/convenient_service/service/plugins/{has_result_method_steps → can_have_method_steps}/middleware.rb +12 -2
  83. data/lib/convenient_service/service/plugins/can_have_method_steps.rb +3 -0
  84. data/lib/convenient_service/service/plugins/can_have_result_step/middleware.rb +43 -0
  85. data/lib/convenient_service/service/plugins/can_have_result_step.rb +3 -0
  86. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/commands/create_step_class.rb +1 -1
  87. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/concern.rb +10 -10
  88. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method.rb +92 -0
  89. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/commands/cast_method_direction.rb +30 -3
  90. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +113 -0
  91. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/commands/define_method_in_container.rb +3 -3
  92. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/commands.rb +1 -3
  93. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/concern/class_methods.rb +1 -1
  94. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/concern/instance_methods.rb +1 -1
  95. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/concern.rb +1 -1
  96. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/alias.rb +1 -1
  97. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/base.rb +1 -1
  98. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/proc.rb +1 -1
  99. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/raw.rb +1 -1
  100. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +1 -1
  101. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/reassignment.rb +1 -1
  102. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/usual.rb +1 -1
  103. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/directions/base.rb +1 -1
  104. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/directions/input.rb +1 -1
  105. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/directions/output.rb +1 -1
  106. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/base.rb +62 -0
  107. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/base.rb +35 -0
  108. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/proc_value.rb +42 -0
  109. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/raw_value.rb +42 -0
  110. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/reassignment_value.rb +42 -0
  111. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/string_value.rb +42 -0
  112. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/symbol_value.rb +42 -0
  113. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash.rb +8 -0
  114. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/method.rb +40 -0
  115. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/reassignment.rb +40 -0
  116. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +40 -0
  117. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/symbol.rb +40 -0
  118. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories.rb +8 -0
  119. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/key.rb +1 -1
  120. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/name.rb +1 -1
  121. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/values/reassignment.rb +1 -1
  122. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities.rb +1 -0
  123. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/errors.rb +8 -8
  124. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method.rb +1 -1
  125. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/service/class_methods.rb +1 -1
  126. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/service.rb +1 -1
  127. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/commands/cast_params.rb +1 -1
  128. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/commands/extract_params.rb +1 -1
  129. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/concern/instance_methods.rb +1 -1
  130. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/concern.rb +1 -1
  131. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/errors.rb +27 -0
  132. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/aliases.rb +7 -0
  133. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/plugins/can_have_parent_result/middleware.rb +1 -1
  134. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/plugins/has_inspect/concern.rb +1 -1
  135. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/plugins.rb +2 -0
  136. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/structs/params.rb +1 -1
  137. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step.rb +1 -1
  138. data/lib/convenient_service/service/plugins/can_have_steps/entities/step_collection.rb +106 -0
  139. data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/middleware.rb +4 -4
  140. data/lib/convenient_service/service/plugins/can_have_steps.rb +6 -0
  141. data/lib/convenient_service/service/plugins/can_have_stubbed_result/concern.rb +19 -11
  142. data/lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb +3 -3
  143. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +3 -3
  144. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/aliases.rb +7 -0
  145. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +12 -5
  146. 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
  147. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +1 -0
  148. 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
  149. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_code_class.rb +49 -0
  150. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_data_class.rb +49 -0
  151. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_message_class.rb +49 -0
  152. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_status_class.rb +49 -0
  153. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands.rb +7 -0
  154. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/concern/class_methods.rb +69 -0
  155. 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
  156. 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
  157. 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
  158. 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
  159. 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
  160. 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
  161. 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
  162. 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
  163. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern.rb +36 -0
  164. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data.rb +25 -0
  165. 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
  166. 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
  167. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern.rb +36 -0
  168. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message.rb +25 -0
  169. 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
  170. 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
  171. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern.rb +36 -0
  172. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status.rb +25 -0
  173. 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
  174. 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
  175. 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
  176. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/structs.rb +3 -0
  177. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes.rb +8 -0
  178. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +3 -3
  179. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +1 -1
  180. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +3 -1
  181. data/lib/convenient_service/service/plugins/has_result/errors.rb +2 -2
  182. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +16 -0
  183. data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +1 -1
  184. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +1 -1
  185. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +11 -10
  186. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +14 -7
  187. data/lib/convenient_service/service/plugins.rb +3 -2
  188. data/lib/convenient_service/services/run_own_method_in_organizer.rb +1 -1
  189. data/lib/convenient_service/support/abstract_method/errors.rb +1 -1
  190. data/lib/convenient_service/support/arguments.rb +3 -3
  191. data/lib/convenient_service/support/cache/key.rb +3 -3
  192. data/lib/convenient_service/support/cache.rb +1 -1
  193. data/lib/convenient_service/support/castable/errors.rb +2 -2
  194. data/lib/convenient_service/support/counter.rb +212 -0
  195. data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +33 -0
  196. data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +58 -0
  197. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +4 -3
  198. data/lib/convenient_service/support/dependency_container/commands/define_entry.rb +49 -0
  199. data/lib/convenient_service/support/dependency_container/commands.rb +3 -0
  200. data/lib/convenient_service/support/dependency_container/container.rb +23 -0
  201. data/lib/convenient_service/support/dependency_container/entry.rb +22 -0
  202. data/lib/convenient_service/support/dependency_container/errors.rb +5 -5
  203. data/lib/convenient_service/support/dependency_container/import.rb +3 -3
  204. data/lib/convenient_service/support/dependency_container.rb +3 -0
  205. data/lib/convenient_service/support/finite_loop.rb +37 -2
  206. data/lib/convenient_service/support/middleware/stack_builder.rb +1 -1
  207. data/lib/convenient_service/support/not_passed.rb +4 -3
  208. data/lib/convenient_service/support/ruby.rb +31 -0
  209. data/lib/convenient_service/support/safe_method.rb +65 -0
  210. data/lib/convenient_service/support/thread_safe_counter.rb +119 -0
  211. data/lib/convenient_service/support/undefined.rb +4 -3
  212. data/lib/convenient_service/support/unique_value.rb +69 -0
  213. data/lib/convenient_service/support.rb +4 -0
  214. data/lib/convenient_service/utils/array/errors.rb +1 -1
  215. data/lib/convenient_service/utils/array/find_last.rb +1 -1
  216. data/lib/convenient_service/utils/array/find_yield.rb +1 -1
  217. data/lib/convenient_service/utils/object/resolve_class.rb +56 -0
  218. data/lib/convenient_service/utils/object.rb +9 -0
  219. data/lib/convenient_service/version.rb +1 -1
  220. data/lib/convenient_service.rb +6 -0
  221. metadata +129 -86
  222. data/lib/convenient_service/factories/arguments.rb +0 -43
  223. data/lib/convenient_service/factories/results.rb +0 -214
  224. data/lib/convenient_service/factories/services.rb +0 -189
  225. data/lib/convenient_service/factories/step/instance.rb +0 -32
  226. data/lib/convenient_service/factories/step.rb +0 -3
  227. data/lib/convenient_service/factories/steps.rb +0 -126
  228. data/lib/convenient_service/factories.rb +0 -22
  229. data/lib/convenient_service/factory.rb +0 -21
  230. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +0 -3
  231. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +0 -32
  232. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +0 -74
  233. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +0 -34
  234. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +0 -45
  235. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +0 -34
  236. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +0 -77
  237. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +0 -3
  238. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +0 -8
  239. data/lib/convenient_service/service/plugins/has_result_method_steps.rb +0 -3
  240. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +0 -57
  241. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +0 -74
  242. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +0 -78
  243. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +0 -78
  244. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/errors.rb +0 -23
  245. data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +0 -77
  246. data/lib/convenient_service/service/plugins/has_result_steps.rb +0 -6
  247. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/commands.rb +0 -0
  248. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers/reassignment/commands.rb +0 -0
  249. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/callers.rb +0 -0
  250. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/directions.rb +0 -0
  251. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/method/entities/values.rb +0 -0
  252. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/commands.rb +0 -0
  253. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/plugins/can_have_parent_result.rb +0 -0
  254. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/plugins/has_inspect.rb +0 -0
  255. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities/step/structs.rb +0 -0
  256. /data/lib/convenient_service/service/plugins/{has_result_steps → can_have_steps}/entities.rb +0 -0
  257. /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
@@ -48,8 +48,8 @@ module ConvenientService
48
48
  ##
49
49
  # @param index_or_middleware [Integer, ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
50
50
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
51
- # @param args [Array]
52
- # @param block [Proc]
51
+ # @param args [Array<Object>]
52
+ # @param block [Proc, nil]
53
53
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
54
54
  #
55
55
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L88
@@ -69,8 +69,8 @@ module ConvenientService
69
69
  ##
70
70
  # @param index_or_middleware [Integer, ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
71
71
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
72
- # @param args [Array]
73
- # @param block [Proc]
72
+ # @param args [Array<Object>]
73
+ # @param block [Proc, nil]
74
74
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
75
75
  #
76
76
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L97
@@ -83,8 +83,8 @@ module ConvenientService
83
83
 
84
84
  ##
85
85
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
86
- # @param args [Array]
87
- # @param block [Proc]
86
+ # @param args [Array<Object>]
87
+ # @param block [Proc, nil]
88
88
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
89
89
  #
90
90
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L104
@@ -97,8 +97,8 @@ module ConvenientService
97
97
 
98
98
  ##
99
99
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
100
- # @param args [Array]
101
- # @param block [Proc]
100
+ # @param args [Array<Object>]
101
+ # @param block [Proc, nil]
102
102
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
103
103
  #
104
104
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L111
@@ -112,8 +112,8 @@ module ConvenientService
112
112
  ##
113
113
  # @param index_or_middleware [Integer, ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
114
114
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
115
- # @param args [Array]
116
- # @param block [Proc]
115
+ # @param args [Array<Object>]
116
+ # @param block [Proc, nil]
117
117
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
118
118
  #
119
119
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L118
@@ -138,8 +138,8 @@ module ConvenientService
138
138
 
139
139
  ##
140
140
  # @param middleware [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
141
- # @param args [Array]
142
- # @param block [Proc]
141
+ # @param args [Array<Object>]
142
+ # @param block [Proc, nil]
143
143
  # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Stack]
144
144
  #
145
145
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L76
@@ -3,5 +3,6 @@
3
3
  require_relative "entities/caller"
4
4
  require_relative "entities/chain"
5
5
  require_relative "entities/container"
6
+ require_relative "entities/middleware_creator"
6
7
  require_relative "entities/middleware"
7
8
  require_relative "entities/stack"
@@ -93,7 +93,7 @@ module ConvenientService
93
93
  # NOTE: Consider to remove when support for Ruby 2.7 is dropped.
94
94
  #
95
95
  def resolve_super_method(entity)
96
- klass.commit_config!
96
+ klass.commit_config!(trigger: Constants::Triggers::RESOLVE_METHOD_MIDDLEWARES_SUPER_METHOD)
97
97
 
98
98
  container.resolve_super_method(method, entity)
99
99
  end
@@ -5,7 +5,7 @@ module ConvenientService
5
5
  module Entities
6
6
  class Config
7
7
  module Errors
8
- class ConfigIsCommitted < ConvenientService::Error
8
+ class ConfigIsCommitted < ::ConvenientService::Error
9
9
  ##
10
10
  # @param config [ConvenientService::Core::Entities::Config]
11
11
  # @return [void]
@@ -20,6 +20,43 @@ module ConvenientService
20
20
  super(message)
21
21
  end
22
22
  end
23
+
24
+ class TooManyCommitsFromMethodMissing < ::ConvenientService::Error
25
+ ##
26
+ # @param config [ConvenientService::Core::Entities::Config]
27
+ # @return [void]
28
+ #
29
+ # @internal
30
+ # TODO: Create a troubleshooting page with possible reasons (preliminary RSpec mocks etc).
31
+ # Append a link to it to the error message.
32
+ #
33
+ def initialize(config:)
34
+ message = <<~TEXT
35
+ `#{config.klass}` config is committed too many times from `method_missing`.
36
+
37
+ In order to resolve this issue try to commit it manually before usage of any config-dependent method.
38
+
39
+ Example 1 (outside class):
40
+
41
+ # Commitment:
42
+ #{config.klass}.commit_config!
43
+
44
+ # Few lines later - usage:
45
+ #{config.klass}.result # or whatever method.
46
+
47
+ Example 2 (inside class):
48
+
49
+ class #{config.klass}
50
+ # ...
51
+ commit_config!
52
+
53
+ step :result # or any other method that becomes available after config commitment.
54
+ end
55
+ TEXT
56
+
57
+ super(message)
58
+ end
59
+ end
23
60
  end
24
61
  end
25
62
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "config/commands"
3
4
  require_relative "config/entities"
4
5
  require_relative "config/errors"
5
6
 
@@ -57,13 +58,13 @@ module ConvenientService
57
58
  # @overload middlewares(method)
58
59
  # Returns all instance middlewares for particular method.
59
60
  # @param method [Symbol] Method name.
60
- # @return [Hash<Symbol, Hash<Symbol, ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares>>]
61
+ # @return [Hash{Symbol => Hash{Symbol => ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares}}]
61
62
  #
62
63
  # @overload middlewares(method, scope:)
63
64
  # Returns all scoped middlewares for particular method.
64
65
  # @param method [Symbol] Method name.
65
66
  # @param scope [:instance, :class]
66
- # @return [Hash<Symbol, Hash<Symbol, ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares>>]
67
+ # @return [Hash{Symbol => Hash{Symbol => ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares}}]
67
68
  #
68
69
  # @overload middlewares(method, &configuration_block)
69
70
  # Configures instance middlewares for particular method.
@@ -105,6 +106,13 @@ module ConvenientService
105
106
  @middlewares[scope][method] || Entities::MethodMiddlewares.new(scope: scope, method: method, klass: klass)
106
107
  end
107
108
 
109
+ ##
110
+ # @return [ConvenientService::Support::ThreadSafeCounter]
111
+ #
112
+ def method_missing_commits_counter
113
+ @method_missing_commits_counter ||= Support::ThreadSafeCounter.new(max_value: Constants::Commits::METHOD_MISSING_MAX_TRIES)
114
+ end
115
+
108
116
  ##
109
117
  # @return [Boolean]
110
118
  #
@@ -116,18 +124,20 @@ module ConvenientService
116
124
  # Commits config when called for the first time.
117
125
  # Does nothing for the subsequent calls.
118
126
  #
127
+ # @param trigger [ConvenientService::Support::UniqueValue]
119
128
  # @return [Boolean] true if called for the first time, false otherwise (similarly as Kernel#require).
120
129
  #
121
130
  # @see https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-require
122
131
  #
123
- def commit!
132
+ def commit!(trigger: Constants::Triggers::USER)
124
133
  concerns.include!
134
+ .tap { Commands::TrackMethodMissingCommitTrigger.call(config: self, trigger: trigger) }
125
135
  end
126
136
 
127
137
  private
128
138
 
129
139
  ##
130
- # @note: Config is committed either by `commit_config` or `method_missing` from `ConvenientService::Core::ClassMethods`.
140
+ # @note: Config is committed either by `commit_config` or `method_missing` from `ConvenientService::Core::InstanceMethods` and `ConvenientService::Core::ClassMethods`.
131
141
  #
132
142
  # @return [void]
133
143
  # @raise [ConvenientService::Core::Entities::Config::Errors::ConfigIsCommitted]
@@ -31,15 +31,17 @@ module ConvenientService
31
31
  #
32
32
  # @param method [Symbol]
33
33
  # @param args [Array<Object>]
34
- # @param kwargs [Hash<Symbol, Object>]
35
- # @param block [Proc]
34
+ # @param kwargs [Hash{Symbol => Object}]
35
+ # @param block [Proc, nil]
36
36
  # @return [void]
37
37
  #
38
38
  # @internal
39
- # IMPORTANT: `method_missing` should be thread-safe.
39
+ # IMPORTANT: `method_missing` MUST be thread-safe.
40
+ #
41
+ # NOTE: `__send__` is used instead of `Support::SafeMethod` intentionally, since checking whether a method is defined is performed earlier by `Utils::Module.instance_method_defined?`.
40
42
  #
41
43
  def method_missing(method, *args, **kwargs, &block)
42
- self.class.commit_config!
44
+ self.class.commit_config!(trigger: Constants::Triggers::INSTANCE_METHOD_MISSING)
43
45
 
44
46
  return super unless Utils::Module.instance_method_defined?(self.class, method, private: true)
45
47
 
@@ -3,6 +3,7 @@
3
3
  require_relative "core/instance_methods"
4
4
  require_relative "core/class_methods"
5
5
 
6
+ require_relative "core/constants"
6
7
  require_relative "core/entities"
7
8
 
8
9
  require_relative "core/aliases"
@@ -42,3 +42,10 @@ require "rubygems"
42
42
  # - https://github.com/ruby/singleton
43
43
  #
44
44
  require "singleton"
45
+
46
+ ##
47
+ # @internal
48
+ # - https://ruby-doc.org/core-2.7.0/Mutex.html
49
+ # - https://docs.ruby-lang.org/en/2.1.0/Mutex.html
50
+ #
51
+ require "thread"
@@ -3,10 +3,26 @@
3
3
  module ConvenientService
4
4
  module Dependencies
5
5
  module Extractions
6
+ ##
7
+ # @internal
8
+ # NOTE:
9
+ # Copied from `rails/rails` with some logic modification.
10
+ # Version: v7.0.3.1.
11
+ # Wrapped in a namespace `ConvenientService::Dependencies::Extractions::ActiveSupportConcern`.
12
+ # Added `instance_methods` that works in a similar way as `class_methods`.
13
+ # Also `ClassMethods` (and `InstanceMethods`) are loaded after `included` block, not as in the original implementation.
14
+ #
15
+ # - https://github.com/marian13/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
16
+ # - https://github.com/rails/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
17
+ # - https://github.com/rails/rails
18
+ #
19
+ # NOTE: It is ok that `MultipleIncludedBlocks` and `MultiplePrependBlocks` inherit from `StandardError` since dependencies are on the lower layer.
20
+ #
21
+ # TODO: Move `Concern` to support? Rescue and reraise errors?
22
+ # - https://github.com/marian13/convenient_service/wiki/Design:-Communication-Graph
23
+ #
6
24
  module ActiveSupportConcern
7
25
  ##
8
- # https://github.com/marian13/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
9
- #
10
26
  # A typical module looks like this:
11
27
  #
12
28
  # module M
@@ -13,4 +13,8 @@
13
13
  # - https://github.com/rails/rails/blob/v7.0.3.1/activesupport/lib/active_support/concern.rb
14
14
  # - https://github.com/rails/rails
15
15
  #
16
+ # NOTE: It is ok that `MultipleIncludedBlocks` and `MultiplePrependBlocks` inherit from `StandardError` since dependencies are on the lower layer.
17
+ # TODO: Move `Concern` to support? Rescue and reraise errors?
18
+ # - https://github.com/marian13/convenient_service/wiki/Design:-Communication-Graph
19
+ #
16
20
  require_relative "active_support_concern/concern"
@@ -5,7 +5,13 @@ module ConvenientService
5
5
  module Extractions
6
6
  module RubyMiddleware
7
7
  ##
8
- # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb
8
+ # @internal
9
+ # NOTE:
10
+ # Copied from `Ibsciss/ruby-middleware` without any logic modification.
11
+ # Version: v0.4.2.
12
+ # - Wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
13
+ #
14
+ # - https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb
9
15
  #
10
16
  module Middleware
11
17
  # This provides a DSL for building up a stack of middlewares.
@@ -6,7 +6,13 @@ module ConvenientService
6
6
  module Extractions
7
7
  module RubyMiddleware
8
8
  ##
9
- # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/logger.rb
9
+ # @internal
10
+ # NOTE:
11
+ # Copied from `Ibsciss/ruby-middleware` without any logic modification.
12
+ # Version: v0.4.2.
13
+ # - Wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
14
+ #
15
+ # - https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/logger.rb
10
16
  #
11
17
  module Middleware
12
18
 
@@ -3,7 +3,14 @@ module ConvenientService
3
3
  module Extractions
4
4
  module RubyMiddleware
5
5
  ##
6
- # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/runner.rb
6
+ # @internal
7
+ # NOTE:
8
+ # Copied from `Ibsciss/ruby-middleware` without any logic modification.
9
+ # Version: v0.4.2.
10
+ # - Wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
11
+ # - Added support of middleware creators.
12
+ #
13
+ # - https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/runner.rb
7
14
  #
8
15
  module Middleware
9
16
  # This is a basic runner for middleware stacks. This runner does
@@ -60,6 +67,13 @@ module ConvenientService
60
67
  # If the klass actually is a class, then instantiate it with
61
68
  # the app and any other arguments given.
62
69
  klass.new(next_middleware, *args, &block)
70
+ ##
71
+ # IMPORTANT: Customization compared to the original `Runner` implementation.
72
+ #
73
+ # NOTE: Added support of middleware creators.
74
+ #
75
+ elsif klass.respond_to?(:new)
76
+ klass.new(next_middleware, *args, &block)
63
77
  elsif klass.respond_to?(:call)
64
78
  # Make it a lambda which calls the item then forwards up
65
79
  # the chain.
@@ -2,7 +2,14 @@
2
2
 
3
3
  ##
4
4
  # @internal
5
- # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware.rb
5
+ # NOTE:
6
+ # Copied from `Ibsciss/ruby-middleware` without any logic modification.
7
+ # Version: v0.4.2.
8
+ # - Wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
9
+ # - Replaced `require` into `require_relative`.
10
+ # - Added support of middleware creators.
11
+ #
12
+ # - https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware.rb
6
13
  #
7
14
  require_relative "middleware/builder"
8
15
  require_relative "middleware/runner"
@@ -5,8 +5,9 @@
5
5
  # NOTE:
6
6
  # Copied from `Ibsciss/ruby-middleware` without any logic modification.
7
7
  # Version: v0.4.2.
8
- # Just wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
9
- # Replaced `require` into `require_relative`.
8
+ # - Wrapped in a namespace `ConvenientService::Dependencies::Extractions::RubyMiddleware`.
9
+ # - Replaced `require` into `require_relative`.
10
+ # - Added support of middleware creators.
10
11
  #
11
12
  # - https://github.com/marian13/ruby-middleware/blob/v0.4.2
12
13
  # - https://github.com/Ibsciss/ruby-middleware/blob/v0.4.2
@@ -87,15 +87,28 @@ module ConvenientService
87
87
  # @return [Boolean]
88
88
  # @note Expected to be called from `irb`, `pry`, `spec_helper.rb`, etc.
89
89
  #
90
+ # @internal
91
+ # NOTE: `byebug` has C extensions, that is why it is NOT supported in JRuby.
92
+ # - https://github.com/deivid-rodriguez/byebug/tree/master/ext/byebug
93
+ # - https://github.com/deivid-rodriguez/byebug/issues/179#issuecomment-152727003
94
+ #
90
95
  def require_development_tools
91
96
  require "awesome_print"
92
- require "byebug"
97
+ require "byebug" unless ruby.jruby?
93
98
  require "paint"
94
99
  require "rouge"
95
100
  require "tempfile"
96
101
 
97
- require_relative "dependencies/extractions/byebug_syntax_highlighting"
98
- require_relative "dependencies/extractions/b"
102
+ require_relative "dependencies/extractions/byebug_syntax_highlighting" unless ruby.jruby?
103
+ require_relative "dependencies/extractions/b" unless ruby.jruby?
104
+ end
105
+
106
+ ##
107
+ # @return [Boolean]
108
+ # @note Expected to be called from `spec_helper.rb`.
109
+ #
110
+ def require_test_tools
111
+ require "faker"
99
112
  end
100
113
 
101
114
  ##
@@ -114,18 +127,6 @@ module ConvenientService
114
127
  require_relative "rspec"
115
128
  end
116
129
 
117
- ##
118
- # Loads test factory.
119
- #
120
- # @return [Boolean]
121
- # @note Expected to be called from `spec_helper.rb`.
122
- #
123
- def require_factory
124
- require "faker"
125
-
126
- require_relative "factory"
127
- end
128
-
129
130
  ##
130
131
  # Loads standard config examples.
131
132
  #
@@ -14,10 +14,10 @@ module ConvenientService
14
14
  module Examples
15
15
  module Dry
16
16
  module Gemfile
17
- class << self
18
- def format(path)
19
- Services::Format[path: path]
20
- end
17
+ include ConvenientService::Feature
18
+
19
+ entry :format do |path|
20
+ Services::Format[path: path]
21
21
  end
22
22
  end
23
23
  end
@@ -14,10 +14,10 @@ module ConvenientService
14
14
  module Examples
15
15
  module Rails
16
16
  module Gemfile
17
- class << self
18
- def format(path)
19
- Services::Format[path: path]
20
- end
17
+ include ConvenientService::Feature
18
+
19
+ entry :format do |path|
20
+ Services::Format[path: path]
21
21
  end
22
22
  end
23
23
  end
@@ -13,10 +13,10 @@ module ConvenientService
13
13
  module Examples
14
14
  module Standard
15
15
  module Cowsay
16
- class << self
17
- def print(text = "Hello World!", out: $stdout)
18
- Services::Print[text: text, out: out]
19
- end
16
+ include ConvenientService::Feature
17
+
18
+ entry :print do |text = "Hello World!", out: $stdout|
19
+ Services::Print[text: text, out: out]
20
20
  end
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@ module ConvenientService
8
8
  class AssertFileExists
9
9
  include ConvenientService::Standard::Config
10
10
 
11
- attr_accessor :path
11
+ attr_reader :path
12
12
 
13
13
  def initialize(path:)
14
14
  @path = path
@@ -8,7 +8,7 @@ module ConvenientService
8
8
  class AssertFileNotEmpty
9
9
  include ConvenientService::Standard::Config
10
10
 
11
- attr_accessor :path
11
+ attr_reader :path
12
12
 
13
13
  def initialize(path:)
14
14
  @path = path
@@ -13,15 +13,6 @@ module ConvenientService
13
13
  class AssertNodeAvailable
14
14
  include ConvenientService::Standard::Config
15
15
 
16
- ##
17
- # NOTE: `commit_config!` is used explicitly, since `step` method is NOT missed. It will be taken from `Turnip`.
18
- # - https://github.com/jnicklas/turnip/blob/master/lib/turnip.rb#L29
19
- # - https://github.com/jnicklas/turnip/blob/8272ef92902329d2d29bb5ba2b29cd431523478f/lib/turnip/define.rb#L3
20
- #
21
- # TODO: Troubleshooting guide.
22
- #
23
- commit_config!
24
-
25
16
  ##
26
17
  # NOTE: `> /dev/null 2>&1` is used to hide output.
27
18
  # https://unix.stackexchange.com/a/119650/394253
@@ -13,10 +13,10 @@ module ConvenientService
13
13
  module Examples
14
14
  module Standard
15
15
  module Gemfile
16
- class << self
17
- def format(path)
18
- Services::Format[path: path]
19
- end
16
+ include ConvenientService::Feature
17
+
18
+ entry :format do |path|
19
+ Services::Format[path: path]
20
20
  end
21
21
  end
22
22
  end
@@ -37,10 +37,10 @@ module ConvenientService
37
37
  module Examples
38
38
  module Standard
39
39
  module RequestParams
40
- class << self
41
- def prepare(request)
42
- Services::Prepare[request: request]
43
- end
40
+ include ConvenientService::Feature
41
+
42
+ entry :prepare do |request|
43
+ Services::Prepare[request: request]
44
44
  end
45
45
  end
46
46
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Feature
5
+ include Support::Concern
6
+
7
+ included do
8
+ include Support::DependencyContainer::Entry
9
+ include Support::DependencyContainer::Export
10
+ end
11
+ end
12
+ end
@@ -23,15 +23,16 @@ module ConvenientService
23
23
  private
24
24
 
25
25
  ##
26
- # NOTE: `super` is `Logger.new`.
27
- # https://ruby-doc.org/stdlib-3.1.0/libdoc/logger/rdoc/Logger.html#method-c-new
26
+ # @internal
27
+ # NOTE: `super` is `Logger.new`.
28
+ # - https://ruby-doc.org/stdlib-3.1.0/libdoc/logger/rdoc/Logger.html#method-c-new
28
29
  #
29
30
  # rubocop:disable Style/GlobalStdStream
30
31
  def new
31
- super(STDOUT).tap do |logger|
32
- logger.level = ENV["ACTIVE_SERVICE_LOGGER_LEVEL"] || "INFO"
32
+ super(::STDOUT).tap do |logger|
33
+ logger.level = ::ENV["CONVENIENT_SERVICE_LOGGER_LEVEL"] || "INFO"
33
34
 
34
- logger.formatter = colored_formatter if ENV["ACTIVE_SERVICE_LOGGER_ENABLE_COLORS"] == "true"
35
+ logger.formatter = colored_formatter if ::ENV["CONVENIENT_SERVICE_LOGGER_ENABLE_COLORS"] == "true"
35
36
  end
36
37
  end
37
38
  # rubocop:enable Style/GlobalStdStream
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module RSpec
5
+ module Helpers
6
+ module Custom
7
+ # @internal
8
+ # TODO: Specs.
9
+ #
10
+ class InThreads < Support::Command
11
+ ##
12
+ # @!attribute [r] n
13
+ # @return [Integer] Amount of threads.
14
+ #
15
+ attr_reader :n
16
+
17
+ ##
18
+ # @!attribute [r] args
19
+ # @return [Array<Object>] Args passed to `Thread.new`.
20
+ #
21
+ # @internal
22
+ # NOTE: More info about `args`.
23
+ # - https://ruby-doc.org/core-2.7.0/Thread.html#method-c-new
24
+ #
25
+ attr_reader :args
26
+
27
+ ##
28
+ # @!attribute [r] block
29
+ # @return [Proc] Block passed to `Thread.new`.
30
+ #
31
+ # @internal
32
+ # NOTE: More info about `block`.
33
+ # - https://ruby-doc.org/core-2.7.0/Thread.html#method-c-new
34
+ #
35
+ attr_reader :block
36
+
37
+ ##
38
+ # @param n [Integer] Amount of threads.
39
+ # @param args [Array<Object>] Args passed to `Thread.new`.
40
+ # @param block [Proc, nil] Block passed to `Thread.new`.
41
+ # @return [void]
42
+ #
43
+ def initialize(n, *args, &block)
44
+ @n = n
45
+ @args = args
46
+ @block = block
47
+ end
48
+
49
+ ##
50
+ # @return [Array<Object>] Thread values. Can be any type.
51
+ #
52
+ # @internal
53
+ # NOTE: `thread.value` calls `thread.join` under the hood. That is why it is missed here.
54
+ # - https://ruby-doc.org/core-2.7.0/Thread.html#method-i-value
55
+ #
56
+ # TODO: Thread pool? Why?
57
+ # - https://github.com/toy/in_threads/blob/master/lib/in_threads.rb
58
+ #
59
+ def call
60
+ threads = []
61
+
62
+ ##
63
+ # NOTE: CRuby has GIL, so the specs are almost always successful for simple cases.
64
+ # NOTE: JRuby or TruffleRuby use real threads, so NOT thread-safe code starts to fail even for the simplest cases.
65
+ #
66
+ n.times { threads << ::Thread.new(*args, &block) }
67
+
68
+ threads.map(&:value)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end