convenient_service 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/.dev/.tmuxinator.yml +2 -1
  3. data/.github/workflows/ci.yml +21 -1
  4. data/CHANGELOG.md +67 -0
  5. data/Gemfile +6 -0
  6. data/README.md +4 -2
  7. data/Taskfile.yml +94 -0
  8. data/convenient_service.gemspec +40 -2
  9. data/docker/2.7/Dockerfile +3 -3
  10. data/docker/3.0/Dockerfile +2 -2
  11. data/docker/3.1/Dockerfile +2 -2
  12. data/docker/3.2/Dockerfile +73 -0
  13. data/docker/jruby-9.4/Dockerfile +88 -0
  14. data/docker/truffleruby-22.3/Dockerfile +91 -0
  15. data/lib/convenient_service/common/plugins/aliases.rb +0 -1
  16. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb +12 -8
  17. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +3 -3
  18. data/lib/convenient_service/common/plugins/can_have_user_provided_entity/errors.rb +2 -2
  19. data/lib/convenient_service/common/plugins/has_around_callbacks/errors.rb +1 -1
  20. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +7 -7
  21. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/aliases.rb +7 -0
  22. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb +2 -0
  23. data/lib/convenient_service/configs/minimal.rb +19 -10
  24. data/lib/convenient_service/core/class_methods.rb +24 -9
  25. data/lib/convenient_service/core/constants.rb +36 -0
  26. data/lib/convenient_service/core/entities/config/commands/track_method_missing_commit_trigger.rb +69 -0
  27. data/lib/convenient_service/core/entities/config/commands.rb +3 -0
  28. data/lib/convenient_service/core/entities/config/entities/concerns/entities/stack.rb +10 -10
  29. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb +3 -3
  30. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb +18 -1
  31. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware_creator.rb +62 -0
  32. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/stack.rb +12 -12
  33. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities.rb +1 -0
  34. data/lib/convenient_service/core/entities/config/entities/method_middlewares.rb +1 -1
  35. data/lib/convenient_service/core/entities/config/errors.rb +38 -1
  36. data/lib/convenient_service/core/entities/config.rb +14 -4
  37. data/lib/convenient_service/core/instance_methods.rb +6 -4
  38. data/lib/convenient_service/core.rb +1 -0
  39. data/lib/convenient_service/dependencies/built_in.rb +7 -0
  40. data/lib/convenient_service/dependencies/extractions/active_support_concern/concern.rb +18 -2
  41. data/lib/convenient_service/dependencies/extractions/active_support_concern.rb +4 -0
  42. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/builder.rb +7 -1
  43. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/logger.rb +7 -1
  44. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb +15 -1
  45. data/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware.rb +8 -1
  46. data/lib/convenient_service/dependencies/extractions/ruby_middleware.rb +3 -2
  47. data/lib/convenient_service/dependencies.rb +16 -15
  48. data/lib/convenient_service/examples/dry/gemfile.rb +4 -4
  49. data/lib/convenient_service/examples/rails/gemfile.rb +4 -4
  50. data/lib/convenient_service/examples/standard/cowsay.rb +4 -4
  51. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb +1 -1
  52. data/lib/convenient_service/examples/standard/gemfile/services/assert_file_not_empty.rb +1 -1
  53. data/lib/convenient_service/examples/standard/gemfile/services/assert_node_available.rb +0 -9
  54. data/lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb +0 -10
  55. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +0 -10
  56. data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +0 -10
  57. data/lib/convenient_service/examples/standard/gemfile/services/parse_content.rb +0 -10
  58. data/lib/convenient_service/examples/standard/gemfile/services/read_file_content.rb +0 -10
  59. data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +0 -10
  60. data/lib/convenient_service/examples/standard/gemfile.rb +4 -4
  61. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +0 -10
  62. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +0 -10
  63. data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +0 -10
  64. data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +0 -10
  65. data/lib/convenient_service/examples/standard/request_params.rb +4 -4
  66. data/lib/convenient_service/feature.rb +12 -0
  67. data/lib/convenient_service/logger.rb +6 -5
  68. data/lib/convenient_service/rspec/helpers/custom/in_threads.rb +74 -0
  69. data/lib/convenient_service/rspec/helpers/custom/stub_service/constants.rb +20 -0
  70. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/stubbed_service.rb +4 -4
  71. data/lib/convenient_service/rspec/helpers/custom/stub_service.rb +1 -0
  72. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +3 -3
  73. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +1 -1
  74. data/lib/convenient_service/rspec/helpers/custom.rb +1 -0
  75. data/lib/convenient_service/rspec/helpers/in_threads.rb +13 -0
  76. data/lib/convenient_service/rspec/helpers.rb +2 -0
  77. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +3 -3
  78. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +3 -3
  79. data/lib/convenient_service/rspec/matchers/custom/export.rb +82 -0
  80. data/lib/convenient_service/rspec/matchers/custom/results/base/constants.rb +22 -0
  81. data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +1 -1
  82. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +2 -1
  83. data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
  84. data/lib/convenient_service/rspec/matchers/export.rb +13 -0
  85. data/lib/convenient_service/rspec/matchers.rb +2 -0
  86. data/lib/convenient_service/service/plugins/aliases.rb +0 -2
  87. data/lib/convenient_service/service/plugins/can_have_method_steps/middleware.rb +2 -2
  88. data/lib/convenient_service/service/plugins/can_have_result_step/middleware.rb +2 -2
  89. data/lib/convenient_service/service/plugins/can_have_steps/concern.rb +2 -2
  90. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method.rb +46 -11
  91. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_direction.rb +29 -2
  92. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_factory.rb +113 -0
  93. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands.rb +1 -3
  94. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/base.rb +62 -0
  95. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/base.rb +35 -0
  96. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/proc_value.rb +42 -0
  97. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/raw_value.rb +42 -0
  98. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/reassignment_value.rb +42 -0
  99. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/string_value.rb +42 -0
  100. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash/symbol_value.rb +42 -0
  101. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/hash.rb +8 -0
  102. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/method.rb +40 -0
  103. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/reassignment.rb +40 -0
  104. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/string.rb +40 -0
  105. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories/symbol.rb +40 -0
  106. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities/factories.rb +8 -0
  107. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/entities.rb +1 -0
  108. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/errors.rb +7 -7
  109. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/errors.rb +12 -8
  110. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins/aliases.rb +7 -0
  111. data/lib/convenient_service/service/plugins/can_have_steps/entities/step/plugins.rb +2 -0
  112. data/lib/convenient_service/service/plugins/can_have_steps/entities/step_collection.rb +37 -8
  113. data/lib/convenient_service/service/plugins/can_have_stubbed_result/concern.rb +19 -11
  114. data/lib/convenient_service/service/plugins/can_have_stubbed_result/middleware.rb +3 -3
  115. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +3 -3
  116. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/aliases.rb +7 -0
  117. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +12 -5
  118. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/concern/class_methods.rb → can_have_parent_result/constants.rb} +3 -4
  119. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +1 -0
  120. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb → has_j_send_status_and_attributes/commands/cast_j_send_attributes.rb} +1 -1
  121. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_code_class.rb +49 -0
  122. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_data_class.rb +49 -0
  123. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_message_class.rb +49 -0
  124. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands/create_status_class.rb +49 -0
  125. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/commands.rb +7 -0
  126. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/concern/class_methods.rb +69 -0
  127. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern/instance_methods.rb +9 -9
  128. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/concern.rb +1 -1
  129. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/class_methods.rb +2 -2
  130. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern/instance_methods.rb +3 -3
  131. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code/concern.rb +1 -1
  132. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities/code.rb +1 -1
  133. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/class_methods.rb +38 -0
  134. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern/instance_methods.rb +94 -0
  135. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/concern.rb +36 -0
  136. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data.rb +25 -0
  137. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/class_methods.rb +40 -0
  138. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern/instance_methods.rb +58 -0
  139. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/concern.rb +36 -0
  140. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message.rb +25 -0
  141. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/class_methods.rb +40 -0
  142. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern/instance_methods.rb +115 -0
  143. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/concern.rb +36 -0
  144. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status.rb +25 -0
  145. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/errors.rb +6 -2
  146. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/middleware.rb +4 -4
  147. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes/structs/jsend_attributes.rb → has_j_send_status_and_attributes/structs/j_send_attributes.rb} +1 -1
  148. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/structs.rb +3 -0
  149. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes.rb +8 -0
  150. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb +3 -3
  151. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb +1 -1
  152. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +3 -1
  153. data/lib/convenient_service/service/plugins/has_result/errors.rb +2 -2
  154. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +16 -0
  155. data/lib/convenient_service/service/plugins/raises_on_double_result/errors.rb +1 -1
  156. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb +1 -1
  157. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb +11 -10
  158. data/lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/middleware.rb +14 -7
  159. data/lib/convenient_service/services/run_own_method_in_organizer.rb +1 -1
  160. data/lib/convenient_service/support/abstract_method/errors.rb +1 -1
  161. data/lib/convenient_service/support/arguments.rb +3 -3
  162. data/lib/convenient_service/support/cache/key.rb +3 -3
  163. data/lib/convenient_service/support/cache.rb +1 -1
  164. data/lib/convenient_service/support/castable/errors.rb +2 -2
  165. data/lib/convenient_service/support/counter.rb +212 -0
  166. data/lib/convenient_service/support/dependency_container/commands/assert_valid_container.rb +33 -0
  167. data/lib/convenient_service/support/dependency_container/commands/assert_valid_method.rb +58 -0
  168. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +4 -3
  169. data/lib/convenient_service/support/dependency_container/commands/define_entry.rb +49 -0
  170. data/lib/convenient_service/support/dependency_container/commands.rb +3 -0
  171. data/lib/convenient_service/support/dependency_container/container.rb +23 -0
  172. data/lib/convenient_service/support/dependency_container/entry.rb +22 -0
  173. data/lib/convenient_service/support/dependency_container/errors.rb +5 -5
  174. data/lib/convenient_service/support/dependency_container/import.rb +3 -3
  175. data/lib/convenient_service/support/dependency_container.rb +3 -0
  176. data/lib/convenient_service/support/finite_loop.rb +37 -2
  177. data/lib/convenient_service/support/middleware/stack_builder.rb +1 -1
  178. data/lib/convenient_service/support/not_passed.rb +4 -3
  179. data/lib/convenient_service/support/ruby.rb +31 -0
  180. data/lib/convenient_service/support/safe_method.rb +65 -0
  181. data/lib/convenient_service/support/thread_safe_counter.rb +119 -0
  182. data/lib/convenient_service/support/undefined.rb +4 -3
  183. data/lib/convenient_service/support/unique_value.rb +69 -0
  184. data/lib/convenient_service/support.rb +4 -0
  185. data/lib/convenient_service/utils/array/errors.rb +1 -1
  186. data/lib/convenient_service/utils/array/find_last.rb +1 -1
  187. data/lib/convenient_service/utils/array/find_yield.rb +1 -1
  188. data/lib/convenient_service/utils/object/resolve_class.rb +56 -0
  189. data/lib/convenient_service/utils/object.rb +9 -0
  190. data/lib/convenient_service/version.rb +1 -1
  191. data/lib/convenient_service.rb +6 -0
  192. metadata +75 -34
  193. data/lib/convenient_service/factories/arguments.rb +0 -43
  194. data/lib/convenient_service/factories/results.rb +0 -214
  195. data/lib/convenient_service/factories/services.rb +0 -229
  196. data/lib/convenient_service/factories/step/instance.rb +0 -42
  197. data/lib/convenient_service/factories/step.rb +0 -3
  198. data/lib/convenient_service/factories/steps.rb +0 -126
  199. data/lib/convenient_service/factories.rb +0 -22
  200. data/lib/convenient_service/factory.rb +0 -21
  201. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_caller.rb +0 -74
  202. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_key.rb +0 -78
  203. data/lib/convenient_service/service/plugins/can_have_steps/entities/method/commands/cast_method_name.rb +0 -78
  204. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +0 -3
  205. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +0 -32
  206. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +0 -74
  207. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +0 -34
  208. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +0 -45
  209. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +0 -34
  210. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +0 -77
  211. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +0 -3
  212. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +0 -8
  213. /data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/{has_jsend_status_and_attributes → has_j_send_status_and_attributes}/entities.rb +0 -0
@@ -0,0 +1,91 @@
1
+ ##
2
+ # TruffleRuby 22.3 (CRuby 3.1 compatible) with Node.js 16.x.
3
+ # - https://github.com/graalvm/container/blob/master/truffleruby/README.md
4
+ # - https://github.com/oracle/truffleruby/blob/master/doc/user/compatibility.md
5
+ #
6
+ # NOTE: Linted by hadolint.
7
+ #
8
+ # docker run --rm -i ghcr.io/hadolint/hadolint < docker/truffleruby-22.3/Dockerfile
9
+ #
10
+ # NOTE: A command to build image.
11
+ #
12
+ # cd convenient_service
13
+ # cp Gemfile Gemfile.truffleruby-22.3
14
+ # docker build . -f docker/truffleruby-22.3/Dockerfile -t convenient_service:truffleruby-22.3
15
+ # # or `task docker:build:jruby_9.4`
16
+ #
17
+ # NOTE: A command to run bash in container.
18
+ #
19
+ # cd convenient_service
20
+ # docker run --rm -it -v $(pwd):/gem convenient_service:truffleruby-22.3 bash
21
+ # # or `task docker:bash:jruby_9.4`
22
+ #
23
+ # NOTE: If there are no memory, performance, or cost constraints, prefer to use as standard Linux distribution as it is possible.
24
+ # In a general case, you simply won't have enough time to resolve all the "quirks" of more specific distributions if you are an application developer.
25
+ # `ghcr.io/graalvm/truffleruby:debian-22.3` uses Debian (that is similar to Ubuntu) under the hood.
26
+ # - https://github.com/graalvm/container/pkgs/container/truffleruby/65464856?tag=debian-22.3
27
+ # - https://github.com/graalvm/container/blob/master/truffleruby/Dockerfile.debian#L6
28
+ # - https://www.graalvm.org/latest/docs/getting-started/container-images/
29
+ #
30
+ # NOTE: Gallium means Node.js 16.x.
31
+ # https://github.com/nodejs/Release
32
+ #
33
+ FROM ghcr.io/graalvm/truffleruby:debian-22.3
34
+
35
+ ##
36
+ # NOTE: `git`, `make`, `gcc` are `bundle install` dependencies.
37
+ #
38
+ # NOTE: `curl` and `gnupg2` are Node.js 16.x dependencies.
39
+ # https://github.com/timbru31/docker-ruby-node/blob/master/3.2/16/slim/Dockerfile
40
+ #
41
+ RUN apt-get update -qq \
42
+ && apt-get install --no-install-recommends -y git \
43
+ && apt-get install --no-install-recommends -y make \
44
+ && apt-get install --no-install-recommends -y gcc \
45
+ && apt-get install --no-install-recommends -y curl \
46
+ && apt-get install --no-install-recommends -y gnupg2 \
47
+ && apt-get clean \
48
+ && rm -rf /var/lib/apt/lists/*
49
+
50
+ RUN mkdir -p /gem
51
+
52
+ WORKDIR /gem
53
+
54
+ COPY . /gem
55
+
56
+ ##
57
+ # NOTE: Every container has its own copy of `Gemfile`. This way a developer doesn't need to delete `Gemfile.lock` all the time when changing containers.
58
+ # - https://docs.docker.com/engine/reference/builder/#env
59
+ # - https://stackoverflow.com/questions/48863711/is-it-possible-to-koverride-gemfile-for-local-development
60
+ #
61
+ ENV BUNDLE_GEMFILE=Gemfile.truffleruby-22.3
62
+
63
+ RUN bundle install
64
+
65
+ RUN bundle exec appraisal install
66
+
67
+ ##
68
+ # NOTE: Installs `task`.
69
+ # https://taskfile.dev/installation/#install-script
70
+ #
71
+ # NOTE: `task` is installed into `~/bin`. That is why `-b /bin` is used. See `echo ${PATH}` to debug.
72
+ #
73
+ RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /bin
74
+
75
+ ##
76
+ # NOTE: Intalls Node.js 16.x and `yarn`.
77
+ # https://github.com/timbru31/docker-ruby-node/blob/master/3.2/16/slim/Dockerfile
78
+ #
79
+ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -\
80
+ && apt-get update -qq \
81
+ && apt-get install -qq --no-install-recommends nodejs \
82
+ && apt-get upgrade -qq \
83
+ && apt-get clean \
84
+ && rm -rf /var/lib/apt/lists/*\
85
+ && npm install -g yarn@1
86
+
87
+ ##
88
+ # NOTE: Is used to check whether a command is executed inside a Docker container. See Rakefile for examples.
89
+ # https://stackoverflow.com/a/65942222/12201472
90
+ #
91
+ ENV IN_DOCKER_CONTAINER=true
@@ -3,6 +3,5 @@
3
3
  module ConvenientService
4
4
  module Plugins
5
5
  Common = ::ConvenientService::Common::Plugins
6
- Internals = ::ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins
7
6
  end
8
7
  end
@@ -7,18 +7,22 @@ module ConvenientService
7
7
  module UsingActiveModelAttributeAssignment
8
8
  class Middleware < Core::MethodChainMiddleware
9
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
10
+ # @param args [Array<Object>]
11
+ # @param kwargs [Hash{Symbol => Object}]
12
+ # @param block [Proc, nil]
13
+ # @return [void]
14
+ #
15
+ # @internal
16
+ # TODO: Consider creation of a plugin that assigns `*args` with `assign_attributes` as well, not only `**kwargs`.
17
+ # Check `Method#parameters` for a possible solution.
18
+ # - https://ruby-doc.org/core-3.1.0/Method.html#method-i-parameters
19
+ #
20
+ # NOTE: `assign_attributes` expects `attr_writer` for all `kwargs` keys.
21
+ # - https://api.rubyonrails.org/classes/ActiveModel/AttributeAssignment.html#method-i-assign_attributes
13
22
  #
14
23
  def next(*args, **kwargs, &block)
15
24
  chain.next(*args, **kwargs, &block)
16
25
 
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
26
  entity.assign_attributes(kwargs)
23
27
  end
24
28
  end
@@ -6,9 +6,9 @@ module ConvenientService
6
6
  module CachesReturnValue
7
7
  class Middleware < Core::MethodChainMiddleware
8
8
  ##
9
- # @param args [Array]
10
- # @param kwargs [Hash]
11
- # @param block [Proc]
9
+ # @param args [Array<Object>]
10
+ # @param kwargs [Hash{Symbol => Object}]
11
+ # @param block [Proc, nil]
12
12
  # @return [Object] Can be any type.
13
13
  #
14
14
  def next(*args, **kwargs, &block)
@@ -5,7 +5,7 @@ module ConvenientService
5
5
  module Plugins
6
6
  module CanHaveUserProvidedEntity
7
7
  module Errors
8
- class ProtoEntityHasNoName < ConvenientService::Error
8
+ class ProtoEntityHasNoName < ::ConvenientService::Error
9
9
  def initialize(proto_entity:)
10
10
  message = <<~TEXT
11
11
  Proto entity `#{proto_entity}` has no name.
@@ -22,7 +22,7 @@ module ConvenientService
22
22
  end
23
23
  end
24
24
 
25
- class ProtoEntityHasNoConcern < ConvenientService::Error
25
+ class ProtoEntityHasNoConcern < ::ConvenientService::Error
26
26
  def initialize(proto_entity:)
27
27
  message = <<~TEXT
28
28
  Proto entity `#{proto_entity}` has no concern.
@@ -5,7 +5,7 @@ module ConvenientService
5
5
  module Plugins
6
6
  module HasAroundCallbacks
7
7
  module Errors
8
- class AroundCallbackChainIsNotContinued < ConvenientService::Error
8
+ class AroundCallbackChainIsNotContinued < ::ConvenientService::Error
9
9
  def initialize(callback:)
10
10
  message = <<~TEXT
11
11
  Around callback chain is NOT continued from `#{callback.block.source_location}`.
@@ -20,7 +20,7 @@ module ConvenientService
20
20
 
21
21
  ##
22
22
  # @param types [ConvenientService::Common::Plugins::HasCallbacks::Entities::TypeCollection]
23
- # @param block [Proc]
23
+ # @param block [Proc, nil]
24
24
  # @return [void]
25
25
  #
26
26
  def initialize(types:, block:)
@@ -74,9 +74,9 @@ module ConvenientService
74
74
 
75
75
  ##
76
76
  # @param context [Object] Can be any type.
77
- # @param args [Array]
78
- # @param kwargs [Hash]
79
- # @param block [Proc]
77
+ # @param args [Array<Object>]
78
+ # @param kwargs [Hash{Symbol => Object}]
79
+ # @param block [Proc, nil]
80
80
  # @return [ConvenientService::Common::Plugins::HasCallbacks::Entities::Callback]
81
81
  #
82
82
  def call_in_context_with_arguments(context, *args, **kwargs, &block)
@@ -86,9 +86,9 @@ module ConvenientService
86
86
  ##
87
87
  # @param context [Object] Can be any type.
88
88
  # @param value [Object] Can be any type.
89
- # @param args [Array]
90
- # @param kwargs [Hash]
91
- # @param block [Proc]
89
+ # @param args [Array<Object>]
90
+ # @param kwargs [Hash{Symbol => Object}]
91
+ # @param block [Proc, nil]
92
92
  # @return [ConvenientService::Common::Plugins::HasCallbacks::Entities::Callback]
93
93
  #
94
94
  def call_in_context_with_value_and_arguments(context, value, *args, **kwargs, &block)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Plugins
5
+ Internals = ::ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins
6
+ end
7
+ end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "plugins/has_cache"
4
+
5
+ require_relative "plugins/aliases"
@@ -71,14 +71,7 @@ module ConvenientService
71
71
  middlewares :step, scope: :class do
72
72
  use Plugins::Common::NormalizesEnv::Middleware
73
73
 
74
- ##
75
- # IMPORTANT:
76
- # - `CanHaveMethodSteps` is disabled in the Standard config since it causes race conditions in combination with `CanHaveStubbedResult`.
77
- # - It will be reenabled after the introduction of thread-safety specs.
78
- # - Do not use it in production yet.
79
- #
80
- # use Plugins::Service::CanHaveMethodSteps::Middleware
81
-
74
+ use Plugins::Service::CanHaveMethodSteps::Middleware
82
75
  use Plugins::Service::CanHaveResultStep::Middleware
83
76
  end
84
77
 
@@ -100,13 +93,13 @@ module ConvenientService
100
93
 
101
94
  use Plugins::Common::HasConstructor::Concern
102
95
 
103
- use Plugins::Result::HasJsendStatusAndAttributes::Concern
96
+ use Plugins::Result::HasJSendStatusAndAttributes::Concern
104
97
  end
105
98
 
106
99
  middlewares :initialize do
107
100
  use Plugins::Common::NormalizesEnv::Middleware
108
101
 
109
- use Plugins::Result::HasJsendStatusAndAttributes::Middleware
102
+ use Plugins::Result::HasJSendStatusAndAttributes::Middleware
110
103
  end
111
104
 
112
105
  middlewares :success? do
@@ -149,6 +142,22 @@ module ConvenientService
149
142
  use Plugins::Common::NormalizesEnv::Middleware
150
143
  end
151
144
 
145
+ class self::Data
146
+ include Core
147
+ end
148
+
149
+ class self::Message
150
+ include Core
151
+ end
152
+
153
+ class self::Code
154
+ include Core
155
+ end
156
+
157
+ class self::Status
158
+ include Core
159
+ end
160
+
152
161
  class self::Internals
153
162
  include Core
154
163
 
@@ -6,28 +6,41 @@ module ConvenientService
6
6
  ##
7
7
  # @see ConvenientService::Core::Entities::Config#concerns
8
8
  #
9
+ # @internal
10
+ # NOTE: The instance variable is named `@__convenient_service_config__` intentionally in order to decrease the possibility of accidental redefinition by the end-user.
11
+ # NOTE: An `attr_reader` for `@__convenient_service_config__` is NOT created intentionally in order to NOT pollute the end-user class interface.
12
+ #
9
13
  def concerns(...)
10
- (@__config__ ||= Entities::Config.new(klass: self)).concerns(...)
14
+ (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).concerns(...)
11
15
  end
12
16
 
13
17
  ##
14
18
  # @see ConvenientService::Core::Entities::Config#middlewares
15
19
  #
20
+ # @internal
21
+ # NOTE: The instance variable is named `@__convenient_service_config__` intentionally in order to decrease the possibility of accidental redefinition by the end-user.
22
+ # NOTE: An `attr_reader` for `@__convenient_service_config__` is NOT created intentionally in order to NOT pollute the end-user class interface.
23
+ #
16
24
  def middlewares(...)
17
- (@__config__ ||= Entities::Config.new(klass: self)).middlewares(...)
25
+ (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).middlewares(...)
18
26
  end
19
27
 
20
28
  ##
21
29
  # Commits config when called for the first time.
22
30
  # Does nothing for the subsequent calls.
23
31
  #
32
+ # @param trigger [ConvenientService::Support::UniqueValue]
24
33
  # @return [Boolean] true if called for the first time, false otherwise (similarly as Kernel#require).
25
34
  #
26
35
  # @see https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-require
27
36
  #
28
- def commit_config!
29
- (@__config__ ||= Entities::Config.new(klass: self)).commit!
30
- .tap { ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `.commit_config!`" } }
37
+ # @internal
38
+ # NOTE: The instance variable is named `@__convenient_service_config__` intentionally in order to decrease the possibility of accidental redefinition by the end-user.
39
+ # NOTE: An `attr_reader` for `@__convenient_service_config__` is NOT created intentionally in order to NOT pollute the end-user class interface.
40
+ #
41
+ def commit_config!(trigger: ConvenientService::Core::Constants::Triggers::USER)
42
+ (@__convenient_service_config__ ||= Entities::Config.new(klass: self)).commit!(trigger: trigger)
43
+ .tap { ConvenientService.logger.debug { "[Core] Committed config for `#{self}` | Triggered by `.commit_config!(trigger: #{trigger.inspect})` " } }
31
44
  end
32
45
 
33
46
  ##
@@ -58,15 +71,17 @@ module ConvenientService
58
71
  #
59
72
  # @param method [Symbol]
60
73
  # @param args [Array<Object>]
61
- # @param kwargs [Hash<Symbol, Object>]
62
- # @param block [Proc]
74
+ # @param kwargs [Hash{Symbol => Object}]
75
+ # @param block [Proc, nil]
63
76
  # @return [void]
64
77
  #
65
78
  # @internal
66
- # IMPORTANT: `method_missing` should be thread-safe.
79
+ # IMPORTANT: `method_missing` MUST be thread-safe.
80
+ #
81
+ # NOTE: `__send__` is used instead of `Support::SafeMethod` intentionally, since checking whether a method is defined is performed earlier by `Utils::Module.class_method_defined?`.
67
82
  #
68
83
  def method_missing(method, *args, **kwargs, &block)
69
- commit_config!
84
+ commit_config!(trigger: Constants::Triggers::CLASS_METHOD_MISSING)
70
85
 
71
86
  return super unless Utils::Module.class_method_defined?(self, method, private: true)
72
87
 
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Core
5
+ module Constants
6
+ module Commits
7
+ ##
8
+ # @return [Integer]
9
+ #
10
+ METHOD_MISSING_MAX_TRIES = 10
11
+ end
12
+
13
+ module Triggers
14
+ ##
15
+ # @return [ConvenientService::Support::UniqueValue]
16
+ #
17
+ CLASS_METHOD_MISSING = Support::UniqueValue.new("CLASS_METHOD_MISSING")
18
+
19
+ ##
20
+ # @return [ConvenientService::Support::UniqueValue]
21
+ #
22
+ INSTANCE_METHOD_MISSING = Support::UniqueValue.new("INSTANCE_METHOD_MISSING")
23
+
24
+ ##
25
+ # @return [ConvenientService::Support::UniqueValue]
26
+ #
27
+ RESOLVE_METHOD_MIDDLEWARES_SUPER_METHOD = Support::UniqueValue.new("RESOLVE_METHOD_MIDDLEWARES_SUPER_METHOD")
28
+
29
+ ##
30
+ # @return [ConvenientService::Support::UniqueValue]
31
+ #
32
+ USER = Support::UniqueValue.new("USER")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Core
5
+ module Entities
6
+ class Config
7
+ module Commands
8
+ class TrackMethodMissingCommitTrigger < Support::Command
9
+ ##
10
+ # @!attribute [r] config
11
+ # @return [ConvenientService::Core::Entities::Config]
12
+ #
13
+ attr_reader :config
14
+
15
+ ##
16
+ # @!attribute [r] trigger
17
+ # @return [ConvenientService::Support::UniqueValue]
18
+ #
19
+ attr_reader :trigger
20
+
21
+ ##
22
+ # @param config [ConvenientService::Core::Entities::Config]
23
+ # @param trigger [ConvenientService::Support::UniqueValue]
24
+ # @return [void]
25
+ #
26
+ def initialize(config:, trigger:)
27
+ @config = config
28
+ @trigger = trigger
29
+ end
30
+
31
+ ##
32
+ # @return [void]
33
+ #
34
+ def call
35
+ return unless method_missing_trigger_valid?
36
+ return if method_missing_commits_counter_incremented?
37
+
38
+ raise Errors::TooManyCommitsFromMethodMissing.new(config: config)
39
+ end
40
+
41
+ ##
42
+ # @return [Boolean]
43
+ #
44
+ def method_missing_trigger_valid?
45
+ method_missing_triggers.any?(trigger)
46
+ end
47
+
48
+ ##
49
+ # @return [Boolean]
50
+ #
51
+ def method_missing_commits_counter_incremented?
52
+ Utils::Object.memoize_including_falsy_values(self, :@method_missing_commits_counter_incremented) { config.method_missing_commits_counter.bincrement }
53
+ end
54
+
55
+ ##
56
+ # @return [Array<ConvenientService::Support::UniqueValue>]
57
+ #
58
+ def method_missing_triggers
59
+ @method_missing_triggers ||= [
60
+ Constants::Triggers::INSTANCE_METHOD_MISSING,
61
+ Constants::Triggers::CLASS_METHOD_MISSING
62
+ ]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "commands/track_method_missing_commit_trigger"
@@ -51,8 +51,8 @@ module ConvenientService
51
51
  ##
52
52
  # @param index_or_concern [Integer, ConvenientService::Support::Concern, Module]
53
53
  # @param concern [ConvenientService::Support::Concern, Module]
54
- # @param args [Array]
55
- # @param block [Proc]
54
+ # @param args [Array<Object>]
55
+ # @param block [Proc, nil]
56
56
  # @return [ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Stack]
57
57
  #
58
58
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L88
@@ -72,8 +72,8 @@ module ConvenientService
72
72
  ##
73
73
  # @param index_or_concern [Integer, ConvenientService::Support::Concern, Module]
74
74
  # @param concern [ConvenientService::Support::Concern, Module]
75
- # @param args [Array]
76
- # @param block [Proc]
75
+ # @param args [Array<Object>]
76
+ # @param block [Proc, nil]
77
77
  # @return [ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Stack]
78
78
  #
79
79
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L97
@@ -86,8 +86,8 @@ module ConvenientService
86
86
 
87
87
  ##
88
88
  # @param concern [ConvenientService::Support::Concern, Module]
89
- # @param args [Array]
90
- # @param block [Proc]
89
+ # @param args [Array<Object>]
90
+ # @param block [Proc, nil]
91
91
  # @return [ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Stack]
92
92
  #
93
93
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L104
@@ -113,8 +113,8 @@ module ConvenientService
113
113
  ##
114
114
  # @param index_or_concern [Integer, ConvenientService::Support::Concern, Module]
115
115
  # @param concern [ConvenientService::Support::Concern, Module]
116
- # @param args [Array]
117
- # @param block [Proc]
116
+ # @param args [Array<Object>]
117
+ # @param block [Proc, nil]
118
118
  # @return [ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Stack]
119
119
  #
120
120
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L118
@@ -139,8 +139,8 @@ module ConvenientService
139
139
 
140
140
  ##
141
141
  # @param concern [ConvenientService::Support::Concern, Module]
142
- # @param args [Array]
143
- # @param block [Proc]
142
+ # @param args [Array<Object>]
143
+ # @param block [Proc, nil]
144
144
  # @return [ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::Stack]
145
145
  #
146
146
  # @see https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L76
@@ -23,9 +23,9 @@ module ConvenientService
23
23
  end
24
24
 
25
25
  ##
26
- # @param args [Array]
27
- # @param kwargs [Hash]
28
- # @param block [Proc]
26
+ # @param args [Array<Object>]
27
+ # @param kwargs [Hash{Symbol => Object}]
28
+ # @param block [Proc, nil]
29
29
  # @return [Object] Can be any type.
30
30
  #
31
31
  # @internal
@@ -43,13 +43,23 @@ module ConvenientService
43
43
  #
44
44
  abstract_method :next
45
45
 
46
+ class << self
47
+ ##
48
+ # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::MiddlewareCreator]
49
+ #
50
+ def with(...)
51
+ Entities::MiddlewareCreator.new(middleware: self, arguments: Support::Arguments.new(...))
52
+ end
53
+ end
54
+
46
55
  ##
47
56
  # @param stack [#call<Hash>]
48
57
  # @return [void]
49
58
  #
50
- def initialize(stack, env: {})
59
+ def initialize(stack, env: {}, arguments: Support::Arguments.null_arguments)
51
60
  @__stack__ = stack
52
61
  @__env__ = env
62
+ @__arguments__ = arguments
53
63
  end
54
64
 
55
65
  ##
@@ -104,6 +114,13 @@ module ConvenientService
104
114
  def chain
105
115
  @__chain__ ||= Entities::Chain.new(stack: @__stack__)
106
116
  end
117
+
118
+ ##
119
+ # @return [ConvenientService::Support::Arguments]
120
+ #
121
+ def arguments
122
+ @__arguments__
123
+ end
107
124
  end
108
125
  end
109
126
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Core
5
+ module Entities
6
+ class Config
7
+ module Entities
8
+ class MethodMiddlewares
9
+ module Entities
10
+ class MiddlewareCreator
11
+ ##
12
+ # @!attribute [r] middleware
13
+ # @return [Class]
14
+ #
15
+ attr_reader :middleware
16
+
17
+ ##
18
+ # @!attribute [r] arguments
19
+ # @return [ConvenientService::Support::Arguments]
20
+ #
21
+ attr_reader :arguments
22
+
23
+ ##
24
+ # @param middleware [Class]
25
+ # @param arguments [ConvenientService::Support::Arguments]
26
+ # @return [void]
27
+ #
28
+ def initialize(middleware:, arguments:)
29
+ @middleware = middleware
30
+ @arguments = arguments
31
+ end
32
+
33
+ ##
34
+ # @param other [Object]
35
+ # @return [Boolean, nil]
36
+ #
37
+ def ==(other)
38
+ return unless other.instance_of?(self.class)
39
+
40
+ return false if middleware != other.middleware
41
+ return false if arguments != other.arguments
42
+
43
+ true
44
+ end
45
+
46
+ ##
47
+ # @param stack [#call<Hash>]
48
+ # @param env [Hash]
49
+ # @param arguments [ConvenientService::Support::Arguments]
50
+ # @return [ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware]
51
+ #
52
+ def new(stack, env: {}, arguments: self.arguments)
53
+ middleware.new(stack, env: env, arguments: arguments)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end