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
@@ -7,7 +7,7 @@ module ConvenientService
7
7
  module Entities
8
8
  class Result
9
9
  module Plugins
10
- module HasJsendStatusAndAttributes
10
+ module HasJSendStatusAndAttributes
11
11
  module Concern
12
12
  ##
13
13
  # TODO: How to use concern outside?
@@ -52,42 +52,42 @@ module ConvenientService
52
52
  delegate :service, to: :jsend_attributes
53
53
 
54
54
  ##
55
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Status]
55
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status]
56
56
  #
57
57
  delegate :status, to: :jsend_attributes
58
58
 
59
59
  ##
60
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
60
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Data]
61
61
  #
62
62
  delegate :data, to: :jsend_attributes
63
63
 
64
64
  ##
65
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Data]
65
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Data]
66
66
  #
67
67
  alias_method :unsafe_data, :data
68
68
 
69
69
  ##
70
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
70
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message]
71
71
  #
72
72
  delegate :message, to: :jsend_attributes
73
73
 
74
74
  ##
75
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Message]
75
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message]
76
76
  #
77
77
  alias_method :unsafe_message, :message
78
78
 
79
79
  ##
80
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
80
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code]
81
81
  #
82
82
  delegate :code, to: :jsend_attributes
83
83
 
84
84
  ##
85
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code]
85
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code]
86
86
  #
87
87
  alias_method :unsafe_code, :code
88
88
 
89
89
  ##
90
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Structs::JSendAttributes]
90
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Structs::JSendAttributes]
91
91
  #
92
92
  def jsend_attributes
93
93
  internals.cache[:jsend_attributes]
@@ -10,7 +10,7 @@ module ConvenientService
10
10
  module Entities
11
11
  class Result
12
12
  module Plugins
13
- module HasJsendStatusAndAttributes
13
+ module HasJSendStatusAndAttributes
14
14
  module Concern
15
15
  include Support::Concern
16
16
 
@@ -7,14 +7,14 @@ module ConvenientService
7
7
  module Entities
8
8
  class Result
9
9
  module Plugins
10
- module HasJsendStatusAndAttributes
10
+ module HasJSendStatusAndAttributes
11
11
  module Entities
12
12
  class Code
13
13
  module Concern
14
14
  module ClassMethods
15
15
  ##
16
16
  # @param other [Object] Can be any type.
17
- # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Entities::Code, nil]
17
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code, nil]
18
18
  #
19
19
  def cast(other)
20
20
  case other
@@ -7,13 +7,13 @@ module ConvenientService
7
7
  module Entities
8
8
  class Result
9
9
  module Plugins
10
- module HasJsendStatusAndAttributes
10
+ module HasJSendStatusAndAttributes
11
11
  module Entities
12
12
  class Code
13
13
  module Concern
14
14
  module InstanceMethods
15
15
  ##
16
- # @!attribute value [r]
16
+ # @!attribute [r] value
17
17
  # @return [Symbol]
18
18
  #
19
19
  attr_reader :value
@@ -28,7 +28,7 @@ module ConvenientService
28
28
 
29
29
  ##
30
30
  # @param other [Object] Can be any type.
31
- # @return [Boolean]
31
+ # @return [Boolean, nil]
32
32
  #
33
33
  def ==(other)
34
34
  casted = cast(other)
@@ -10,7 +10,7 @@ module ConvenientService
10
10
  module Entities
11
11
  class Result
12
12
  module Plugins
13
- module HasJsendStatusAndAttributes
13
+ module HasJSendStatusAndAttributes
14
14
  module Entities
15
15
  class Code
16
16
  module Concern
@@ -9,7 +9,7 @@ module ConvenientService
9
9
  module Entities
10
10
  class Result
11
11
  module Plugins
12
- module HasJsendStatusAndAttributes
12
+ module HasJSendStatusAndAttributes
13
13
  module Entities
14
14
  class Code
15
15
  include Concern
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Data
13
+ module Concern
14
+ module ClassMethods
15
+ ##
16
+ # @param other [Object] Can be any type.
17
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Data, nil]
18
+ #
19
+ def cast(other)
20
+ case other
21
+ when ::Hash
22
+ new(value: other.transform_keys(&:to_sym))
23
+ when Data
24
+ new(value: other.value)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Data
13
+ module Concern
14
+ module InstanceMethods
15
+ ##
16
+ # @!attribute [r] value
17
+ # @return [Hash]
18
+ #
19
+ attr_reader :value
20
+
21
+ ##
22
+ # @param value [Hash]
23
+ # @return [void]
24
+ #
25
+ # @internal
26
+ # NOTE: Ruby hashes enumerate their values in the order that the corresponding keys were inserted.
27
+ # That is why the end-user can be 100% sure that the failure message is always generated from the first key/value pair.
28
+ # - https://ruby-doc.org/core-2.7.0/Hash.html
29
+ #
30
+ # TODO: A test that crashes when such behaviour is broken.
31
+ #
32
+ # NOTE: As a result, there is NO need to use any custom `OrderedHash` implementations.
33
+ # - https://api.rubyonrails.org/v5.1/classes/ActiveSupport/OrderedHash.html
34
+ # - https://github.com/rails/rails/issues/22681
35
+ # - https://api.rubyonrails.org/classes/ActiveSupport/OrderedOptions.html
36
+ #
37
+ def initialize(value:)
38
+ @value = value
39
+ end
40
+
41
+ ##
42
+ # @param key [String, Symbol]
43
+ # @return [Boolean]
44
+ #
45
+ def has_attribute?(key)
46
+ value.has_key?(key.to_sym)
47
+ end
48
+
49
+ ##
50
+ # @param other [Object] Can be any type.
51
+ # @return [Boolean, nil]
52
+ #
53
+ def ==(other)
54
+ casted = cast(other)
55
+
56
+ return unless casted
57
+
58
+ value == casted.value
59
+ end
60
+
61
+ ##
62
+ # @param key [String, Symbol]
63
+ # @return [Object] Can be any type.
64
+ # @raise [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Errors::NotExistingAttribute]
65
+ #
66
+ def [](key)
67
+ value.fetch(key.to_sym) { raise Errors::NotExistingAttribute.new(attribute: key) }
68
+ end
69
+
70
+ ##
71
+ # @return [Hash]
72
+ #
73
+ def to_h
74
+ @to_h ||= value.to_h
75
+ end
76
+
77
+ ##
78
+ # @return [String]
79
+ #
80
+ def to_s
81
+ @to_s ||= to_h.to_s
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "concern/class_methods"
4
+ require_relative "concern/instance_methods"
5
+
6
+ module ConvenientService
7
+ module Service
8
+ module Plugins
9
+ module HasResult
10
+ module Entities
11
+ class Result
12
+ module Plugins
13
+ module HasJSendStatusAndAttributes
14
+ module Entities
15
+ class Data
16
+ module Concern
17
+ include Support::Concern
18
+
19
+ included do |code_class|
20
+ code_class.include Support::Castable
21
+
22
+ code_class.include InstanceMethods
23
+
24
+ code_class.extend ClassMethods
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "data/concern"
4
+
5
+ module ConvenientService
6
+ module Service
7
+ module Plugins
8
+ module HasResult
9
+ module Entities
10
+ class Result
11
+ module Plugins
12
+ module HasJSendStatusAndAttributes
13
+ module Entities
14
+ class Data
15
+ include Concern
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Message
13
+ module Concern
14
+ module ClassMethods
15
+ ##
16
+ # @param other [Object] Can be any type.
17
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message, nil]
18
+ #
19
+ def cast(other)
20
+ case other
21
+ when ::String
22
+ new(value: other)
23
+ when ::Symbol
24
+ new(value: other.to_s)
25
+ when Message
26
+ new(value: other.value)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Message
13
+ module Concern
14
+ module InstanceMethods
15
+ ##
16
+ # @!attribute [r] value
17
+ # @return [String]
18
+ #
19
+ attr_reader :value
20
+
21
+ ##
22
+ # @param value [String]
23
+ # @return [void]
24
+ #
25
+ def initialize(value:)
26
+ @value = value
27
+ end
28
+
29
+ ##
30
+ # @param other [Object] Can be any type.
31
+ # @return [Boolean, nil]
32
+ #
33
+ def ==(other)
34
+ casted = cast(other)
35
+
36
+ return unless casted
37
+
38
+ value == casted.value
39
+ end
40
+
41
+ ##
42
+ # @return [String]
43
+ #
44
+ def to_s
45
+ @to_s ||= value.to_s
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "concern/class_methods"
4
+ require_relative "concern/instance_methods"
5
+
6
+ module ConvenientService
7
+ module Service
8
+ module Plugins
9
+ module HasResult
10
+ module Entities
11
+ class Result
12
+ module Plugins
13
+ module HasJSendStatusAndAttributes
14
+ module Entities
15
+ class Message
16
+ module Concern
17
+ include Support::Concern
18
+
19
+ included do |code_class|
20
+ code_class.include Support::Castable
21
+
22
+ code_class.include InstanceMethods
23
+
24
+ code_class.extend ClassMethods
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "message/concern"
4
+
5
+ module ConvenientService
6
+ module Service
7
+ module Plugins
8
+ module HasResult
9
+ module Entities
10
+ class Result
11
+ module Plugins
12
+ module HasJSendStatusAndAttributes
13
+ module Entities
14
+ class Message
15
+ include Concern
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Status
13
+ module Concern
14
+ module ClassMethods
15
+ ##
16
+ # @param other [Object] Can be any type.
17
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status, nil]
18
+ #
19
+ def cast(other)
20
+ case other
21
+ when ::String
22
+ new(value: other.to_sym)
23
+ when ::Symbol
24
+ new(value: other)
25
+ when Status
26
+ new(value: other.value)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Service
5
+ module Plugins
6
+ module HasResult
7
+ module Entities
8
+ class Result
9
+ module Plugins
10
+ module HasJSendStatusAndAttributes
11
+ module Entities
12
+ class Status
13
+ module Concern
14
+ module InstanceMethods
15
+ ##
16
+ # @!attribute [r] value
17
+ # @return [String]
18
+ #
19
+ attr_reader :value
20
+
21
+ ##
22
+ # @param value [String]
23
+ # @return [void]
24
+ #
25
+ def initialize(value:)
26
+ @value = value
27
+ end
28
+
29
+ ##
30
+ # @param other [Object] Can be any type.
31
+ # @return [Boolean, nil]
32
+ #
33
+ def ==(other)
34
+ casted = cast(other)
35
+
36
+ return unless casted
37
+
38
+ value == casted.value
39
+ end
40
+
41
+ ##
42
+ # @return [Boolean]
43
+ #
44
+ def success?
45
+ value == :success
46
+ end
47
+
48
+ ##
49
+ # @return [Boolean]
50
+ #
51
+ def failure?
52
+ value == :failure
53
+ end
54
+
55
+ ##
56
+ # @return [Boolean]
57
+ #
58
+ def error?
59
+ value == :error
60
+ end
61
+
62
+ ##
63
+ # @return [Boolean]
64
+ #
65
+ def not_success?
66
+ !success?
67
+ end
68
+
69
+ ##
70
+ # @return [Boolean]
71
+ #
72
+ def not_failure?
73
+ !failure?
74
+ end
75
+
76
+ ##
77
+ # @return [Boolean]
78
+ #
79
+ def not_error?
80
+ !error?
81
+ end
82
+
83
+ ##
84
+ # @param statuses [Array<Symbol, String, ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Status>]
85
+ # @return [Boolean]
86
+ #
87
+ def in?(statuses)
88
+ statuses.any? { |status| self == status }
89
+ end
90
+
91
+ ##
92
+ # @return [String]
93
+ #
94
+ def to_s
95
+ @to_s ||= value.to_s
96
+ end
97
+
98
+ ##
99
+ # @return [Symbol]
100
+ #
101
+ def to_sym
102
+ @to_sym ||= value.to_sym
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end