convenient_service 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +1 -0
  3. data/.gem_release.yml +23 -0
  4. data/.github/workflows/cd.yml +54 -0
  5. data/.github/workflows/ci.yml +190 -0
  6. data/.gitignore +34 -0
  7. data/.inch.yml +7 -0
  8. data/.rspec +3 -0
  9. data/.rubocop.yml +45 -0
  10. data/.rubocop_rspec.yml +58 -0
  11. data/.ruby-version +1 -0
  12. data/.tool-versions +1 -0
  13. data/.yardopts +13 -0
  14. data/Appraisals +124 -0
  15. data/CHANGELOG.md +1 -0
  16. data/Gemfile +6 -0
  17. data/LICENSE.txt +21 -0
  18. data/README.md +55 -0
  19. data/ROADMAP.md +41 -0
  20. data/Rakefile +54 -0
  21. data/Taskfile.yml +316 -0
  22. data/convenient_service.gemspec +52 -0
  23. data/coverage/.gitkeep +0 -0
  24. data/docker/2.7/Dockerfile +73 -0
  25. data/docker/3.0/Dockerfile +73 -0
  26. data/docker/3.1/Dockerfile +73 -0
  27. data/env.rb +19 -0
  28. data/lib/convenient_service/common/plugins/aliases.rb +8 -0
  29. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +21 -0
  30. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb +29 -0
  31. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment.rb +4 -0
  32. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +21 -0
  33. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer.rb +3 -0
  34. data/lib/convenient_service/common/plugins/caches_constructor_params/concern.rb +22 -0
  35. data/lib/convenient_service/common/plugins/caches_constructor_params/entities/constructor_params.rb +34 -0
  36. data/lib/convenient_service/common/plugins/caches_constructor_params/entities.rb +3 -0
  37. data/lib/convenient_service/common/plugins/caches_constructor_params/middleware.rb +17 -0
  38. data/lib/convenient_service/common/plugins/caches_constructor_params.rb +5 -0
  39. data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +79 -0
  40. data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +3 -0
  41. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -0
  42. data/lib/convenient_service/common/plugins/caches_return_value.rb +4 -0
  43. data/lib/convenient_service/common/plugins/can_be_copied/concern.rb +33 -0
  44. data/lib/convenient_service/common/plugins/can_be_copied.rb +3 -0
  45. data/lib/convenient_service/common/plugins/has_around_callbacks/concern.rb +19 -0
  46. data/lib/convenient_service/common/plugins/has_around_callbacks/errors.rb +29 -0
  47. data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +113 -0
  48. data/lib/convenient_service/common/plugins/has_around_callbacks.rb +5 -0
  49. data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/concern.rb +19 -0
  50. data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches/active_model_attributes.rb +45 -0
  51. data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes/patches.rb +3 -0
  52. data/lib/convenient_service/common/plugins/has_attributes/using_active_model_attributes.rb +4 -0
  53. data/lib/convenient_service/common/plugins/has_callbacks/concern.rb +36 -0
  54. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +59 -0
  55. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback_collection.rb +35 -0
  56. data/lib/convenient_service/common/plugins/has_callbacks/entities/type/class_methods.rb +26 -0
  57. data/lib/convenient_service/common/plugins/has_callbacks/entities/type.rb +50 -0
  58. data/lib/convenient_service/common/plugins/has_callbacks/entities/type_collection.rb +33 -0
  59. data/lib/convenient_service/common/plugins/has_callbacks/entities.rb +6 -0
  60. data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +21 -0
  61. data/lib/convenient_service/common/plugins/has_callbacks.rb +5 -0
  62. data/lib/convenient_service/common/plugins/has_constructor/concern.rb +18 -0
  63. data/lib/convenient_service/common/plugins/has_constructor.rb +3 -0
  64. data/lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb +56 -0
  65. data/lib/convenient_service/common/plugins/has_internals/commands.rb +3 -0
  66. data/lib/convenient_service/common/plugins/has_internals/concern.rb +28 -0
  67. data/lib/convenient_service/common/plugins/has_internals/entities/internals/concern.rb +25 -0
  68. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +30 -0
  69. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +81 -0
  70. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +3 -0
  71. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +4 -0
  72. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb +3 -0
  73. data/lib/convenient_service/common/plugins/has_internals/entities/internals.rb +18 -0
  74. data/lib/convenient_service/common/plugins/has_internals/entities.rb +3 -0
  75. data/lib/convenient_service/common/plugins/has_internals.rb +5 -0
  76. data/lib/convenient_service/common/plugins/normalizes_env/middleware.rb +29 -0
  77. data/lib/convenient_service/common/plugins/normalizes_env.rb +3 -0
  78. data/lib/convenient_service/common/plugins.rb +16 -0
  79. data/lib/convenient_service/common.rb +3 -0
  80. data/lib/convenient_service/configs/aliases.rb +7 -0
  81. data/lib/convenient_service/configs/standard.rb +193 -0
  82. data/lib/convenient_service/configs.rb +5 -0
  83. data/lib/convenient_service/core/aliases.rb +9 -0
  84. data/lib/convenient_service/core/class_methods.rb +81 -0
  85. data/lib/convenient_service/core/entities/classic_middleware.rb +32 -0
  86. data/lib/convenient_service/core/entities/config/entities/concerns/entities/default_concern.rb +18 -0
  87. data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware/commands/cast_middleware.rb +78 -0
  88. data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware/commands.rb +3 -0
  89. data/lib/convenient_service/core/entities/config/entities/concerns/entities/middleware.rb +103 -0
  90. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +206 -0
  91. data/lib/convenient_service/core/entities/config/entities/concerns/entities.rb +5 -0
  92. data/lib/convenient_service/core/entities/config/entities/concerns.rb +216 -0
  93. data/lib/convenient_service/core/entities/config/entities/method_middlewares/commands/generate_stack_name.rb +95 -0
  94. data/lib/convenient_service/core/entities/config/entities/method_middlewares/commands.rb +3 -0
  95. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/cast_caller.rb +72 -0
  96. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb +134 -0
  97. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands.rb +4 -0
  98. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/class_methods.rb +29 -0
  99. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern/instance_methods.rb +66 -0
  100. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/concern.rb +32 -0
  101. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller.rb +25 -0
  102. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +71 -0
  103. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +76 -0
  104. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb +72 -0
  105. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands.rb +4 -0
  106. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/class_methods.rb +29 -0
  107. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern/instance_methods.rb +165 -0
  108. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/concern.rb +32 -0
  109. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container.rb +22 -0
  110. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +114 -0
  111. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +193 -0
  112. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +7 -0
  113. data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +182 -0
  114. data/lib/convenient_service/core/entities/config/entities.rb +4 -0
  115. data/lib/convenient_service/core/entities/config/errors.rb +27 -0
  116. data/lib/convenient_service/core/entities/config.rb +147 -0
  117. data/lib/convenient_service/core/entities.rb +4 -0
  118. data/lib/convenient_service/core/instance_methods.rb +54 -0
  119. data/lib/convenient_service/core.rb +19 -0
  120. data/lib/convenient_service/dependencies/built_in.rb +36 -0
  121. data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +258 -0
  122. data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +16 -0
  123. data/lib/convenient_service/dependencies/extractions/b.rb +12 -0
  124. data/lib/convenient_service/dependencies/extractions/byebug_syntax_highlighting.rb +58 -0
  125. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +194 -0
  126. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +60 -0
  127. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +79 -0
  128. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -0
  129. data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +15 -0
  130. data/lib/convenient_service/dependencies/extractions.rb +10 -0
  131. data/lib/convenient_service/dependencies.rb +133 -0
  132. data/lib/convenient_service/error.rb +16 -0
  133. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +43 -0
  134. data/lib/convenient_service/examples/dry/gemfile/dry_service.rb +3 -0
  135. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +29 -0
  136. data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +29 -0
  137. data/lib/convenient_service/examples/dry/gemfile/services/assert_node_available.rb +26 -0
  138. data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +39 -0
  139. data/lib/convenient_service/examples/dry/gemfile/services/assert_valid_ruby_syntax.rb +41 -0
  140. data/lib/convenient_service/examples/dry/gemfile/services/format.rb +37 -0
  141. data/lib/convenient_service/examples/dry/gemfile/services/format_body.rb +93 -0
  142. data/lib/convenient_service/examples/dry/gemfile/services/format_gems_with_envs.rb +96 -0
  143. data/lib/convenient_service/examples/dry/gemfile/services/format_gems_without_envs.rb +84 -0
  144. data/lib/convenient_service/examples/dry/gemfile/services/format_header.rb +74 -0
  145. data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +93 -0
  146. data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +37 -0
  147. data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +31 -0
  148. data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +40 -0
  149. data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +109 -0
  150. data/lib/convenient_service/examples/dry/gemfile/services.rb +17 -0
  151. data/lib/convenient_service/examples/dry/gemfile.rb +24 -0
  152. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +54 -0
  153. data/lib/convenient_service/examples/rails/gemfile/rails_service.rb +3 -0
  154. data/lib/convenient_service/examples/rails/gemfile/services/assert_file_exists.rb +25 -0
  155. data/lib/convenient_service/examples/rails/gemfile/services/assert_file_not_empty.rb +25 -0
  156. data/lib/convenient_service/examples/rails/gemfile/services/assert_node_available.rb +26 -0
  157. data/lib/convenient_service/examples/rails/gemfile/services/assert_npm_package_available.rb +35 -0
  158. data/lib/convenient_service/examples/rails/gemfile/services/assert_valid_ruby_syntax.rb +35 -0
  159. data/lib/convenient_service/examples/rails/gemfile/services/format.rb +37 -0
  160. data/lib/convenient_service/examples/rails/gemfile/services/format_body.rb +79 -0
  161. data/lib/convenient_service/examples/rails/gemfile/services/format_gems_with_envs.rb +82 -0
  162. data/lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb +70 -0
  163. data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +69 -0
  164. data/lib/convenient_service/examples/rails/gemfile/services/parse_content.rb +89 -0
  165. data/lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb +33 -0
  166. data/lib/convenient_service/examples/rails/gemfile/services/read_file_content.rb +27 -0
  167. data/lib/convenient_service/examples/rails/gemfile/services/run_shell.rb +35 -0
  168. data/lib/convenient_service/examples/rails/gemfile/services/strip_comments.rb +107 -0
  169. data/lib/convenient_service/examples/rails/gemfile/services.rb +17 -0
  170. data/lib/convenient_service/examples/rails/gemfile.rb +24 -0
  171. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +30 -0
  172. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +30 -0
  173. data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +35 -0
  174. data/lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb +48 -0
  175. data/lib/convenient_service/examples/standard/gemfile/services/assert_valid_ruby_syntax.rb +39 -0
  176. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +39 -0
  177. data/lib/convenient_service/examples/standard/gemfile/services/format_body.rb +83 -0
  178. data/lib/convenient_service/examples/standard/gemfile/services/format_gems_with_envs.rb +86 -0
  179. data/lib/convenient_service/examples/standard/gemfile/services/format_gems_without_envs.rb +74 -0
  180. data/lib/convenient_service/examples/standard/gemfile/services/format_header.rb +66 -0
  181. data/lib/convenient_service/examples/standard/gemfile/services/parse_content.rb +101 -0
  182. data/lib/convenient_service/examples/standard/gemfile/services/print_shell_command.rb +38 -0
  183. data/lib/convenient_service/examples/standard/gemfile/services/read_file_content.rb +39 -0
  184. data/lib/convenient_service/examples/standard/gemfile/services/run_shell.rb +37 -0
  185. data/lib/convenient_service/examples/standard/gemfile/services/strip_comments.rb +111 -0
  186. data/lib/convenient_service/examples/standard/gemfile/services.rb +17 -0
  187. data/lib/convenient_service/examples/standard/gemfile.rb +23 -0
  188. data/lib/convenient_service/logger.rb +70 -0
  189. data/lib/convenient_service/rspec/helpers/custom/ignoring_error.rb +29 -0
  190. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +119 -0
  191. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +99 -0
  192. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities.rb +4 -0
  193. data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +26 -0
  194. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +80 -0
  195. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities.rb +3 -0
  196. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +25 -0
  197. data/lib/convenient_service/rspec/helpers/custom/wrap_method.rb +27 -0
  198. data/lib/convenient_service/rspec/helpers/custom.rb +5 -0
  199. data/lib/convenient_service/rspec/helpers/ignoring_error.rb +13 -0
  200. data/lib/convenient_service/rspec/helpers/stub_service.rb +29 -0
  201. data/lib/convenient_service/rspec/helpers/wrap_method.rb +13 -0
  202. data/lib/convenient_service/rspec/helpers.rb +21 -0
  203. data/lib/convenient_service/rspec/matchers/be_descendant_of.rb +13 -0
  204. data/lib/convenient_service/rspec/matchers/be_direct_descendant_of.rb +13 -0
  205. data/lib/convenient_service/rspec/matchers/cache_its_value.rb +13 -0
  206. data/lib/convenient_service/rspec/matchers/call_chain_next.rb +13 -0
  207. data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +55 -0
  208. data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +55 -0
  209. data/lib/convenient_service/rspec/matchers/custom/cache_its_value.rb +55 -0
  210. data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +150 -0
  211. data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +255 -0
  212. data/lib/convenient_service/rspec/matchers/custom/extend_module.rb +40 -0
  213. data/lib/convenient_service/rspec/matchers/custom/have_abstract_method.rb +45 -0
  214. data/lib/convenient_service/rspec/matchers/custom/have_alias_method.rb +45 -0
  215. data/lib/convenient_service/rspec/matchers/custom/have_attr_accessor.rb +43 -0
  216. data/lib/convenient_service/rspec/matchers/custom/have_attr_reader.rb +47 -0
  217. data/lib/convenient_service/rspec/matchers/custom/have_attr_writer.rb +47 -0
  218. data/lib/convenient_service/rspec/matchers/custom/include_module.rb +40 -0
  219. data/lib/convenient_service/rspec/matchers/custom/prepend_module.rb +40 -0
  220. data/lib/convenient_service/rspec/matchers/custom/results/be_error.rb +153 -0
  221. data/lib/convenient_service/rspec/matchers/custom/results/be_failure.rb +120 -0
  222. data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +120 -0
  223. data/lib/convenient_service/rspec/matchers/custom/results.rb +5 -0
  224. data/lib/convenient_service/rspec/matchers/custom.rb +16 -0
  225. data/lib/convenient_service/rspec/matchers/delegate_to.rb +13 -0
  226. data/lib/convenient_service/rspec/matchers/extend_module.rb +13 -0
  227. data/lib/convenient_service/rspec/matchers/have_abstract_method.rb +13 -0
  228. data/lib/convenient_service/rspec/matchers/have_alias_method.rb +13 -0
  229. data/lib/convenient_service/rspec/matchers/have_attr_accessor.rb +13 -0
  230. data/lib/convenient_service/rspec/matchers/have_attr_reader.rb +13 -0
  231. data/lib/convenient_service/rspec/matchers/have_attr_writer.rb +13 -0
  232. data/lib/convenient_service/rspec/matchers/include_module.rb +13 -0
  233. data/lib/convenient_service/rspec/matchers/prepend_module.rb +13 -0
  234. data/lib/convenient_service/rspec/matchers/results/be_error.rb +15 -0
  235. data/lib/convenient_service/rspec/matchers/results/be_failure.rb +15 -0
  236. data/lib/convenient_service/rspec/matchers/results/be_success.rb +15 -0
  237. data/lib/convenient_service/rspec/matchers/results.rb +21 -0
  238. data/lib/convenient_service/rspec/matchers.rb +43 -0
  239. data/lib/convenient_service/rspec.rb +4 -0
  240. data/lib/convenient_service/service/plugins/aliases.rb +8 -0
  241. data/lib/convenient_service/service/plugins/can_recalculate_result/concern.rb +26 -0
  242. data/lib/convenient_service/service/plugins/can_recalculate_result.rb +3 -0
  243. data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +56 -0
  244. data/lib/convenient_service/service/plugins/has_result/commands.rb +3 -0
  245. data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +82 -0
  246. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +32 -0
  247. data/lib/convenient_service/service/plugins/has_result/concern.rb +22 -0
  248. data/lib/convenient_service/service/plugins/has_result/constants.rb +33 -0
  249. data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +33 -0
  250. data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +3 -0
  251. data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +64 -0
  252. data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +19 -0
  253. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +30 -0
  254. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +45 -0
  255. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +28 -0
  256. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +45 -0
  257. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +30 -0
  258. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +41 -0
  259. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +30 -0
  260. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +69 -0
  261. data/lib/convenient_service/service/plugins/has_result/entities/result/entities.rb +6 -0
  262. data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +25 -0
  263. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result/concern.rb +27 -0
  264. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result.rb +3 -0
  265. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb +28 -0
  266. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +30 -0
  267. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax.rb +3 -0
  268. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/marks_result_status_as_checked/middleware.rb +25 -0
  269. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/marks_result_status_as_checked.rb +3 -0
  270. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +31 -0
  271. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/middleware.rb +33 -0
  272. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status.rb +4 -0
  273. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +6 -0
  274. data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +17 -0
  275. data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +3 -0
  276. data/lib/convenient_service/service/plugins/has_result/entities/result.rb +22 -0
  277. data/lib/convenient_service/service/plugins/has_result/entities.rb +3 -0
  278. data/lib/convenient_service/service/plugins/has_result/errors.rb +34 -0
  279. data/lib/convenient_service/service/plugins/has_result/middleware.rb +19 -0
  280. data/lib/convenient_service/service/plugins/has_result.rb +8 -0
  281. data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +23 -0
  282. data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +37 -0
  283. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +29 -0
  284. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +30 -0
  285. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_own_method_in_organizer.rb +52 -0
  286. data/lib/convenient_service/service/plugins/has_result_method_steps/services.rb +5 -0
  287. data/lib/convenient_service/service/plugins/has_result_method_steps.rb +5 -0
  288. data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/concern.rb +19 -0
  289. data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations/middleware.rb +35 -0
  290. data/lib/convenient_service/service/plugins/has_result_params_validations/using_active_model_validations.rb +4 -0
  291. data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/concern.rb +22 -0
  292. data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/middleware.rb +39 -0
  293. data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation.rb +4 -0
  294. data/lib/convenient_service/service/plugins/has_result_short_syntax/concern.rb +30 -0
  295. data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands/assert_args_count_lower_than_three.rb +25 -0
  296. data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands/assert_either_args_or_kwargs_are_passed.rb +26 -0
  297. data/lib/convenient_service/service/plugins/has_result_short_syntax/error/commands.rb +4 -0
  298. data/lib/convenient_service/service/plugins/has_result_short_syntax/error/errors.rb +46 -0
  299. data/lib/convenient_service/service/plugins/has_result_short_syntax/error/middleware.rb +27 -0
  300. data/lib/convenient_service/service/plugins/has_result_short_syntax/error.rb +5 -0
  301. data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/commands/refute_kwargs_contain_data_and_extra_keys.rb +29 -0
  302. data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/commands.rb +3 -0
  303. data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/errors.rb +28 -0
  304. data/lib/convenient_service/service/plugins/has_result_short_syntax/failure/middleware.rb +19 -0
  305. data/lib/convenient_service/service/plugins/has_result_short_syntax/failure.rb +5 -0
  306. data/lib/convenient_service/service/plugins/has_result_short_syntax/success/commands/refute_kwargs_contain_data_and_extra_keys.rb +29 -0
  307. data/lib/convenient_service/service/plugins/has_result_short_syntax/success/commands.rb +3 -0
  308. data/lib/convenient_service/service/plugins/has_result_short_syntax/success/errors.rb +28 -0
  309. data/lib/convenient_service/service/plugins/has_result_short_syntax/success/middleware.rb +19 -0
  310. data/lib/convenient_service/service/plugins/has_result_short_syntax/success.rb +5 -0
  311. data/lib/convenient_service/service/plugins/has_result_short_syntax.rb +6 -0
  312. data/lib/convenient_service/service/plugins/has_result_steps/commands/create_step_class.rb +60 -0
  313. data/lib/convenient_service/service/plugins/has_result_steps/commands.rb +3 -0
  314. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +53 -0
  315. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +54 -0
  316. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +67 -0
  317. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_direction.rb +65 -0
  318. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +71 -0
  319. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +74 -0
  320. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +55 -0
  321. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands.rb +8 -0
  322. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/class_methods.rb +21 -0
  323. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/instance_methods.rb +96 -0
  324. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern.rb +29 -0
  325. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/alias.rb +39 -0
  326. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/base.rb +49 -0
  327. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/proc.rb +42 -0
  328. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/raw.rb +42 -0
  329. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/usual.rb +39 -0
  330. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers.rb +7 -0
  331. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/base.rb +33 -0
  332. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/input.rb +31 -0
  333. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions/output.rb +31 -0
  334. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/directions.rb +5 -0
  335. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/key.rb +40 -0
  336. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/name.rb +40 -0
  337. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/raw.rb +48 -0
  338. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +3 -0
  339. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +7 -0
  340. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +127 -0
  341. data/lib/convenient_service/service/plugins/has_result_steps/entities/method.rb +20 -0
  342. data/lib/convenient_service/service/plugins/has_result_steps/entities/service/class_methods.rb +32 -0
  343. data/lib/convenient_service/service/plugins/has_result_steps/entities/service.rb +48 -0
  344. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands/cast_params.rb +61 -0
  345. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands/extract_params.rb +38 -0
  346. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/commands.rb +4 -0
  347. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +138 -0
  348. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern.rb +23 -0
  349. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/errors.rb +23 -0
  350. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/structs/params.rb +17 -0
  351. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/structs.rb +3 -0
  352. data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +20 -0
  353. data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +61 -0
  354. data/lib/convenient_service/service/plugins/has_result_steps/entities.rb +6 -0
  355. data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +26 -0
  356. data/lib/convenient_service/service/plugins/has_result_steps.rb +6 -0
  357. data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +34 -0
  358. data/lib/convenient_service/service/plugins/raises_on_double_result/middleware.rb +33 -0
  359. data/lib/convenient_service/service/plugins/raises_on_double_result.rb +4 -0
  360. data/lib/convenient_service/service/plugins/wraps_result_in_db_transaction/middleware.rb +15 -0
  361. data/lib/convenient_service/service/plugins/wraps_result_in_db_transaction.rb +3 -0
  362. data/lib/convenient_service/service/plugins.rb +14 -0
  363. data/lib/convenient_service/service.rb +3 -0
  364. data/lib/convenient_service/specification.rb +21 -0
  365. data/lib/convenient_service/support/abstract_method/errors.rb +22 -0
  366. data/lib/convenient_service/support/abstract_method.rb +21 -0
  367. data/lib/convenient_service/support/castable/errors.rb +29 -0
  368. data/lib/convenient_service/support/castable.rb +44 -0
  369. data/lib/convenient_service/support/command.rb +25 -0
  370. data/lib/convenient_service/support/concern.rb +11 -0
  371. data/lib/convenient_service/support/copyable.rb +56 -0
  372. data/lib/convenient_service/support/delegate.rb +42 -0
  373. data/lib/convenient_service/support/finite_loop.rb +49 -0
  374. data/lib/convenient_service/support/middleware/stack_builder.rb +78 -0
  375. data/lib/convenient_service/support/middleware.rb +3 -0
  376. data/lib/convenient_service/support.rb +11 -0
  377. data/lib/convenient_service/utils/array/contain_exactly.rb +56 -0
  378. data/lib/convenient_service/utils/array/drop_while.rb +50 -0
  379. data/lib/convenient_service/utils/array/errors.rb +19 -0
  380. data/lib/convenient_service/utils/array/find_last.rb +38 -0
  381. data/lib/convenient_service/utils/array/find_yield.rb +93 -0
  382. data/lib/convenient_service/utils/array/keep_after.rb +41 -0
  383. data/lib/convenient_service/utils/array/merge.rb +77 -0
  384. data/lib/convenient_service/utils/array/rjust.rb +50 -0
  385. data/lib/convenient_service/utils/array/wrap.rb +40 -0
  386. data/lib/convenient_service/utils/array.rb +52 -0
  387. data/lib/convenient_service/utils/bool/to_bool.rb +37 -0
  388. data/lib/convenient_service/utils/bool.rb +15 -0
  389. data/lib/convenient_service/utils/hash/except.rb +46 -0
  390. data/lib/convenient_service/utils/hash.rb +15 -0
  391. data/lib/convenient_service/utils/method/defined.rb +49 -0
  392. data/lib/convenient_service/utils/method.rb +15 -0
  393. data/lib/convenient_service/utils/module/class_method_defined.rb +46 -0
  394. data/lib/convenient_service/utils/module/get_own_const.rb +60 -0
  395. data/lib/convenient_service/utils/module/get_own_instance_method.rb +81 -0
  396. data/lib/convenient_service/utils/module/has_own_instance_method.rb +77 -0
  397. data/lib/convenient_service/utils/module/instance_method_defined.rb +46 -0
  398. data/lib/convenient_service/utils/module.rb +40 -0
  399. data/lib/convenient_service/utils/object/resolve_type.rb +47 -0
  400. data/lib/convenient_service/utils/object.rb +19 -0
  401. data/lib/convenient_service/utils/proc/conjunct.rb +48 -0
  402. data/lib/convenient_service/utils/proc/exec_config.rb +136 -0
  403. data/lib/convenient_service/utils/proc.rb +20 -0
  404. data/lib/convenient_service/utils/string/camelize.rb +56 -0
  405. data/lib/convenient_service/utils/string.rb +15 -0
  406. data/lib/convenient_service/utils.rb +10 -0
  407. data/lib/convenient_service/version.rb +5 -0
  408. data/lib/convenient_service.rb +31 -0
  409. data/logo.png +0 -0
  410. metadata +738 -0
data/env.rb ADDED
@@ -0,0 +1,19 @@
1
+ ##
2
+ # NOTE: Appraisal sets `BUNDLE_GEMFILE` env variable.
3
+ # This is how appraisals can be differentiated from each other.
4
+ # https://github.com/thoughtbot/appraisal/blob/v2.4.1/lib/appraisal/command.rb#L36
5
+ #
6
+ # If `BUNDLE_GEMFILE` is an empty string, then `APPRAISAL_NAME` is resolved to an empty string as well.
7
+ # User passed `APPRAISAL_NAME` has a precedence.
8
+ #
9
+ # IMPORTANT: `APPRAISAL_NAME` env variable should be initialized as far as it is possible.
10
+ #
11
+ # IMPORTANT: ENV variables declared in this file should NOT be used inside the lib folder.
12
+ #
13
+ ENV["APPRAISAL_NAME"] ||= ENV["BUNDLE_GEMFILE"].to_s.then(&File.method(:basename)).then { |name| name.end_with?(".gemfile") ? name.delete_suffix(".gemfile") : "" }
14
+
15
+ ##
16
+ # NOTE: Ruby version may be set by docker.
17
+ # https://github.com/docker-library/ruby/blob/master/3.1/alpine3.16/Dockerfile#L30
18
+ #
19
+ ENV["RUBY_VERSION"] ||= ::RUBY_VERSION
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Plugins
5
+ Common = ::ConvenientService::Common::Plugins
6
+ Internals = ::ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module AssignsAttributesInConstructor
7
+ module UsingActiveModelAttributeAssignment
8
+ module Concern
9
+ include Support::Concern
10
+
11
+ included do |service_class|
12
+ require "active_model"
13
+
14
+ service_class.include ::ActiveModel::AttributeAssignment
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module AssignsAttributesInConstructor
7
+ module UsingActiveModelAttributeAssignment
8
+ class Middleware < Core::MethodChainMiddleware
9
+ ##
10
+ # TODO: Consider creation of a plugin that assigns `*args` with `assign_attributes` as well, not only `**kwargs`.
11
+ # Check `Method#parameters` for a possible solution.
12
+ # https://ruby-doc.org/core-3.1.0/Method.html#method-i-parameters
13
+ #
14
+ def next(*args, **kwargs, &block)
15
+ chain.next(*args, **kwargs, &block)
16
+
17
+ ##
18
+ # NOTE: `assign_attributes` expects `attr_writer` for all `kwargs` keys.
19
+ #
20
+ # https://api.rubyonrails.org/classes/ActiveModel/AttributeAssignment.html#method-i-assign_attributes
21
+ #
22
+ entity.assign_attributes(kwargs)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "using_active_model_attribute_assignment/concern"
4
+ require_relative "using_active_model_attribute_assignment/middleware"
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module AssignsAttributesInConstructor
7
+ module UsingDryInitializer
8
+ module Concern
9
+ include Support::Concern
10
+
11
+ included do |service_class|
12
+ require "dry-initializer"
13
+
14
+ service_class.extend ::Dry::Initializer
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "using_dry_initializer/concern"
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CachesConstructorParams
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ ##
11
+ # TODO: `internals.cache[:constructor_params] || Entities::NullConstructorParams.new`
12
+ #
13
+ instance_methods do
14
+ def constructor_params
15
+ internals.cache[:constructor_params]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CachesConstructorParams
7
+ module Entities
8
+ class ConstructorParams
9
+ attr_reader :args, :kwargs, :block
10
+
11
+ ##
12
+ # TODO: Specs for default values.
13
+ #
14
+ def initialize(args: [], kwargs: {}, block: nil)
15
+ @args = args
16
+ @kwargs = kwargs
17
+ @block = block
18
+ end
19
+
20
+ def ==(other)
21
+ return unless other.instance_of?(self.class)
22
+
23
+ return false if args != other.args
24
+ return false if kwargs != other.kwargs
25
+ return false if block&.source_location != other.block&.source_location
26
+
27
+ true
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "entities/constructor_params"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CachesConstructorParams
7
+ class Middleware < Core::MethodChainMiddleware
8
+ def next(*args, **kwargs, &block)
9
+ entity.internals.cache[:constructor_params] = Entities::ConstructorParams.new(args: args, kwargs: kwargs, block: block)
10
+
11
+ chain.next(*args, **kwargs, &block)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "caches_constructor_params/concern"
4
+ require_relative "caches_constructor_params/entities"
5
+ require_relative "caches_constructor_params/middleware"
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CachesReturnValue
7
+ module Entities
8
+ class Key
9
+ attr_reader :method, :args, :kwargs, :block
10
+
11
+ ##
12
+ #
13
+ #
14
+ def initialize(method:, args:, kwargs:, block:)
15
+ @method = method
16
+ @args = args
17
+ @kwargs = kwargs
18
+ @block = block
19
+ end
20
+
21
+ ##
22
+ #
23
+ #
24
+ def ==(other)
25
+ return unless other.instance_of?(self.class)
26
+
27
+ return false if method != other.method
28
+ return false if args != other.args
29
+ return false if kwargs != other.kwargs
30
+ return false if block&.source_location != other.block&.source_location
31
+
32
+ true
33
+ end
34
+
35
+ ##
36
+ # IMPORTANT: `Key` instances are used as Ruby hash keys.
37
+ #
38
+ # This method is overridden in order to avoid the following case:
39
+ #
40
+ # hash = {}
41
+ #
42
+ # ##
43
+ # # Two equal keys in terms of `==`.
44
+ # #
45
+ # first_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
46
+ # second_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
47
+ #
48
+ # first_key == second_key
49
+ # # => true
50
+ #
51
+ # hash[first_key] = "value"
52
+ #
53
+ # hash[second_key]
54
+ # # => nil # This happens since keys are not equal in terms of `eql?`.
55
+ #
56
+ # NOTE: Ruby hash and Object#hash are not the same things.
57
+ # https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
58
+ # https://belighted.com/blog/overriding-equals-equals/
59
+ #
60
+ def eql?(other)
61
+ return unless other.instance_of?(self.class)
62
+
63
+ hash == other.hash
64
+ end
65
+
66
+ ##
67
+ # NOTE: hash is overridden to treat blocks that were defined at the same location as equal.
68
+ # https://ruby-doc.org/core-3.1.2/Proc.html#method-i-source_location
69
+ # https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
70
+ #
71
+ def hash
72
+ [method, args, kwargs, block&.source_location].hash
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "entities/key"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CachesReturnValue
7
+ class Middleware < Core::MethodChainMiddleware
8
+ def next(*args, **kwargs, &block)
9
+ key = Entities::Key.new(method: method, args: args, kwargs: kwargs, block: block)
10
+
11
+ entity.internals.cache.fetch(key) { chain.next(*args, **kwargs, &block) }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "caches_return_value/entities"
4
+ require_relative "caches_return_value/middleware"
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module CanBeCopied
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ ##
11
+ # NOTE: `CanBeCopied` plugin expects that `CachesConstructorParams` plugin is already used.
12
+ # That is why `constructor_params` method is available.
13
+ #
14
+ instance_methods do
15
+ include Support::Copyable
16
+
17
+ def to_args
18
+ constructor_params.args
19
+ end
20
+
21
+ def to_kwargs
22
+ constructor_params.kwargs
23
+ end
24
+
25
+ def to_block
26
+ constructor_params.block
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "can_be_copied/concern"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasAroundCallbacks
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ class_methods do
11
+ def around(type, &block)
12
+ Plugins::HasCallbacks::Entities::Callback.new(types: [:around, type], block: block).tap { |callback| callbacks << callback }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasAroundCallbacks
7
+ module Errors
8
+ class AroundCallbackChainIsNotContinued < ConvenientService::Error
9
+ def initialize(callback:)
10
+ message = <<~TEXT
11
+ Around callback chain is NOT continued from `#{callback.block.source_location}`.
12
+
13
+ Did you forget to call `chain.yield`? For example:
14
+
15
+ around :result do |chain|
16
+ # ...
17
+ chain.yield
18
+ # ...
19
+ end
20
+ TEXT
21
+
22
+ super(message)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasAroundCallbacks
7
+ class Middleware < Core::MethodChainMiddleware
8
+ def next(...)
9
+ ##
10
+ # A variable that stores return value of middleware `chain.next` aka `original_value`.
11
+ # It is reassigned later by the `initial_around_callback`.
12
+ #
13
+ original_value = nil
14
+
15
+ ##
16
+ # A list of around callbacks.
17
+ #
18
+ around_callbacks = entity.callbacks.for([:around, method])
19
+
20
+ ##
21
+ #
22
+ #
23
+ initial_around_callback = Plugins::HasCallbacks::Entities::Callback.new(
24
+ types: [:around, method],
25
+ block: proc { original_value = chain.next(...) }
26
+ )
27
+
28
+ ##
29
+ # Let's suppose that we have 3 `around` callbacks:
30
+ #
31
+ # class Service
32
+ # # first
33
+ # around do |chain|
34
+ # # part before `chain.yield`
35
+ # original_value = chain.yield
36
+ # # part after `chain.yield`
37
+ # end
38
+ #
39
+ # # second
40
+ # around do |chain|
41
+ # # part before `chain.yield`
42
+ # original_value = chain.yield
43
+ # # part after `chain.yield`
44
+ # end
45
+ #
46
+ # # third
47
+ # around do |chain|
48
+ # # part before `chain.yield`
49
+ # original_value = chain.yield
50
+ # # part after `chain.yield`
51
+ # end
52
+ # end
53
+ #
54
+ # NOTE: if a user forgets to call `chain.yield` - an error is raised.
55
+ #
56
+ # Then `composed` may be built with the following preudocode (that is why `reverse` is needed):
57
+ #
58
+ # composed = original
59
+ # composed = proc { instance_exec(composed, &third) }
60
+ # composed = proc { instance_exec(composed, &second) }
61
+ # composed = proc { instance_exec(composed, &first) }
62
+ #
63
+ # Where `first`, `second`, `third` are taken from `entity.callbacks.for([:around, method])`.
64
+ #
65
+ # Original implementation is modified in order to return `original_value` from all `chain.yield` calls.
66
+ #
67
+ # # Original implementation:
68
+ # composed =
69
+ # callbacks.for([:around, method]).reverse.reduce(original) do |composed, callback|
70
+ # proc { instance_exec(composed, &callback) }
71
+ # end
72
+ #
73
+ # Original implementation is modified for the second time in order to raise an error
74
+ # if a user forgets to call `chain.yield` inside an around callback.
75
+ #
76
+ # rubocop:disable Style/Semicolon
77
+ composed =
78
+ around_callbacks.reverse.reduce(initial_around_callback) do |composed, callback|
79
+ proc { callback.call_in_context(entity, composed); original_value }
80
+ end
81
+ # rubocop:enable Style/Semicolon
82
+
83
+ ##
84
+ # Call sequence:
85
+ #
86
+ # composed.call
87
+ # proc { instance_exec(composed, &first) }.call # part before `chain.yield`
88
+ # proc { instance_exec(composed, &second) }.call # part before `chain.yield`
89
+ # proc { instance_exec(composed, &third) }.call # part before `chain.yield`
90
+ # initial_around_callback
91
+ # proc { instance_exec(composed, &third) }.call # part after `chain.yield`
92
+ # proc { instance_exec(composed, &second) }.call # part after `chain.yield`
93
+ # proc { instance_exec(composed, &first) }.call # part after `chain.yield`
94
+ #
95
+ composed.call
96
+
97
+ ##
98
+ #
99
+ #
100
+ raise Errors::AroundCallbackChainIsNotContinued.new(callback: Utils::Array.find_last(around_callbacks, &:called?)) if around_callbacks.any?(&:not_called?)
101
+
102
+ ##
103
+ #
104
+ #
105
+ raise Errors::AroundCallbackChainIsNotContinued.new(callback: around_callbacks.last) if initial_around_callback.not_called?
106
+
107
+ original_value
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_around_callbacks/concern"
4
+ require_relative "has_around_callbacks/errors"
5
+ require_relative "has_around_callbacks/middleware"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasAttributes
7
+ module UsingActiveModelAttributes
8
+ module Concern
9
+ include Support::Concern
10
+
11
+ included do |service_class|
12
+ service_class.include Patches::ActiveModelAttributes
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasAttributes
7
+ module UsingActiveModelAttributes
8
+ ##
9
+ # TODO: Remove this patch when Rails updates `def initialize(*)` to `def initialize(*args, **kwargs, &block)`.
10
+ # https://github.com/rails/rails/blob/3872bc0e54d32e8bf3a6299b0bfe173d94b072fc/activemodel/lib/active_model/attributes.rb#L78
11
+ #
12
+ module Patches
13
+ ##
14
+ # Copy of `ActiveModel::Attributes`.
15
+ # - https://api.rubyonrails.org/classes/ActiveModel/Attributes/ClassMethods.html
16
+ #
17
+ # - https://github.com/rails/rails/blob/v7.0.0/activemodel/lib/active_model/attributes.rb
18
+ # - https://github.com/rails/rails/blob/v6.1.0/activemodel/lib/active_model/attributes.rbhttps://github.com/rails/rails/blob/v6.1.0/activemodel/lib/active_model/attributes.rb
19
+ # - https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/attributes.rb
20
+ # - https://github.com/rails/rails/blob/v5.2.0/activemodel/lib/active_model/attributes.rb
21
+ #
22
+ ActiveModelAttributes =
23
+ ::ActiveModel::Attributes.dup.tap do |mod|
24
+ mod.module_eval do
25
+ ##
26
+ # NOTE: Overrides `initialize` since current Rails implementation can not accept kwargs.
27
+ #
28
+ # TODO: Open a PR to Rails.
29
+ #
30
+ def initialize(*args, **kwargs, &block)
31
+ ##
32
+ # IMPORTANT: Should be kept in sync with:
33
+ # https://github.com/rails/rails/blob/3872bc0e54d32e8bf3a6299b0bfe173d94b072fc/activemodel/lib/active_model/attributes.rb#L78
34
+ #
35
+ @attributes = self.class._default_attributes.deep_dup
36
+ super
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "patches/active_model_attributes"
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "using_active_model_attributes/concern"
4
+ require_relative "using_active_model_attributes/patches"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasCallbacks
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ instance_methods do
11
+ include Support::Delegate
12
+
13
+ delegate :callbacks, to: :class
14
+ end
15
+
16
+ class_methods do
17
+ ##
18
+ # @api private
19
+ #
20
+ def callbacks
21
+ @__callbacks__ ||= Entities::CallbackCollection.new
22
+ end
23
+
24
+ def before(type, &block)
25
+ Entities::Callback.new(types: [:before, type], block: block).tap { |callback| callbacks << callback }
26
+ end
27
+
28
+ def after(type, &block)
29
+ Entities::Callback.new(types: [:after, type], block: block).tap { |callback| callbacks << callback }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end