convenient_service 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/ROADMAP.md +26 -4
  6. data/Taskfile.yml +30 -0
  7. data/convenient_service.gemspec +5 -2
  8. data/lib/convenient_service/aliases.rb +2 -0
  9. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/concern.rb +0 -2
  10. data/lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_dry_initializer/concern.rb +0 -2
  11. data/lib/convenient_service/common/plugins/has_around_callbacks/middleware.rb +24 -4
  12. data/lib/convenient_service/common/plugins/has_callbacks/container.rb +17 -0
  13. data/lib/convenient_service/common/plugins/has_callbacks/entities/callback.rb +98 -5
  14. data/lib/convenient_service/common/plugins/has_callbacks/middleware.rb +25 -4
  15. data/lib/convenient_service/common/plugins/has_callbacks.rb +1 -0
  16. data/lib/convenient_service/common/plugins.rb +1 -1
  17. data/lib/convenient_service/configs/standard.rb +25 -12
  18. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/resolve_methods_middlewares_callers.rb +1 -24
  19. data/lib/convenient_service/dependencies.rb +19 -0
  20. data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +4 -2
  21. data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +4 -2
  22. data/lib/convenient_service/examples/rails/gemfile/services/format.rb +35 -6
  23. data/lib/convenient_service/examples/rails/gemfile/services/format_header.rb +1 -2
  24. data/lib/convenient_service/examples/rails/gemfile/services/merge_sections.rb +25 -0
  25. data/lib/convenient_service/examples/rails/gemfile/services/replace_file_content.rb +37 -0
  26. data/lib/convenient_service/examples/rails/gemfile/services.rb +8 -4
  27. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +45 -6
  28. data/lib/convenient_service/examples/standard/gemfile/services/merge_sections.rb +52 -0
  29. data/lib/convenient_service/examples/standard/gemfile/services/replace_file_content.rb +48 -0
  30. data/lib/convenient_service/examples/standard/gemfile/services.rb +8 -4
  31. data/lib/convenient_service/examples/standard/request_params/constants.rb +15 -0
  32. data/lib/convenient_service/examples/standard/request_params/entities/description.rb +40 -0
  33. data/lib/convenient_service/examples/standard/request_params/entities/format.rb +40 -0
  34. data/lib/convenient_service/examples/standard/request_params/entities/id.rb +47 -0
  35. data/lib/convenient_service/examples/standard/request_params/entities/logger.rb +21 -0
  36. data/lib/convenient_service/examples/standard/request_params/entities/request.rb +23 -0
  37. data/lib/convenient_service/examples/standard/request_params/entities/source.rb +40 -0
  38. data/lib/convenient_service/examples/standard/request_params/entities/tag.rb +40 -0
  39. data/lib/convenient_service/examples/standard/request_params/entities/title.rb +40 -0
  40. data/lib/convenient_service/examples/standard/request_params/entities.rb +11 -0
  41. data/lib/convenient_service/examples/standard/request_params/services/apply_default_param_values.rb +26 -0
  42. data/lib/convenient_service/examples/standard/request_params/services/cast_params.rb +38 -0
  43. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_body.rb +70 -0
  44. data/lib/convenient_service/examples/standard/request_params/services/extract_params_from_path.rb +62 -0
  45. data/lib/convenient_service/examples/standard/request_params/services/filter_out_unpermitted_params.rb +26 -0
  46. data/lib/convenient_service/examples/standard/request_params/services/log_request_params.rb +54 -0
  47. data/lib/convenient_service/examples/standard/request_params/services/merge_params.rb +26 -0
  48. data/lib/convenient_service/examples/standard/request_params/services/prepare.rb +65 -0
  49. data/lib/convenient_service/examples/standard/request_params/services/validate_casted_params.rb +94 -0
  50. data/lib/convenient_service/examples/standard/request_params/services/validate_uncasted_params.rb +72 -0
  51. data/lib/convenient_service/examples/standard/request_params/services.rb +13 -0
  52. data/lib/convenient_service/examples/standard/request_params/utils/array/wrap.rb +46 -0
  53. data/lib/convenient_service/examples/standard/request_params/utils/array.rb +21 -0
  54. data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_body.rb +42 -0
  55. data/lib/convenient_service/examples/standard/request_params/utils/http/request/parse_path.rb +40 -0
  56. data/lib/convenient_service/examples/standard/request_params/utils/http/request.rb +28 -0
  57. data/lib/convenient_service/examples/standard/request_params/utils/http.rb +3 -0
  58. data/lib/convenient_service/examples/standard/request_params/utils/integer/safe_parse.rb +31 -0
  59. data/lib/convenient_service/examples/standard/request_params/utils/integer.rb +25 -0
  60. data/lib/convenient_service/examples/standard/request_params/utils/json/safe_parse.rb +40 -0
  61. data/lib/convenient_service/examples/standard/request_params/utils/json.rb +21 -0
  62. data/lib/convenient_service/examples/standard/request_params/utils/object/blank.rb +34 -0
  63. data/lib/convenient_service/examples/standard/request_params/utils/object/present.rb +31 -0
  64. data/lib/convenient_service/examples/standard/request_params/utils/object.rb +26 -0
  65. data/lib/convenient_service/examples/standard/request_params/utils.rb +7 -0
  66. data/lib/convenient_service/examples/standard/request_params.rb +48 -0
  67. data/lib/convenient_service/factories/arguments.rb +43 -0
  68. data/lib/convenient_service/factories/results.rb +214 -0
  69. data/lib/convenient_service/factories/services.rb +189 -0
  70. data/lib/convenient_service/factories/step/instance.rb +32 -0
  71. data/lib/convenient_service/factories/step.rb +3 -0
  72. data/lib/convenient_service/factories/steps.rb +126 -0
  73. data/lib/convenient_service/factories.rb +22 -0
  74. data/lib/convenient_service/factory.rb +21 -0
  75. data/lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb +2 -2
  76. data/lib/convenient_service/rspec/matchers/custom/be_direct_descendant_of.rb +2 -2
  77. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/commands/generate_printable_method.rb +50 -0
  78. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/commands.rb +3 -0
  79. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb +78 -0
  80. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/generate_printable_arguments.rb +100 -0
  81. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands.rb +4 -0
  82. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments.rb +95 -0
  83. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/base.rb +87 -0
  84. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/return_its_value.rb +129 -0
  85. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_any_arguments.rb +37 -0
  86. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_concrete_arguments.rb +37 -0
  87. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/sub_matchers/without_arguments.rb +37 -0
  88. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/base.rb +41 -0
  89. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/with_calling_original.rb +30 -0
  90. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings/values/without_calling_original.rb +30 -0
  91. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings.rb +12 -0
  92. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection/errors.rb +57 -0
  93. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/chainings_collection.rb +171 -0
  94. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities/delegation.rb +79 -0
  95. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher/entities.rb +5 -0
  96. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities/matcher.rb +276 -0
  97. data/lib/convenient_service/rspec/matchers/custom/delegate_to/entities.rb +3 -0
  98. data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +66 -233
  99. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_method_step.rb +74 -0
  100. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_result_method_step.rb +66 -0
  101. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/find_result_service_step.rb +48 -0
  102. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_expected_step_part.rb +42 -0
  103. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/generate_got_step_part.rb +42 -0
  104. data/lib/convenient_service/rspec/matchers/custom/results/base/commands/match_result_step.rb +89 -0
  105. data/lib/convenient_service/rspec/matchers/custom/results/base/commands.rb +10 -0
  106. data/lib/convenient_service/rspec/matchers/custom/results/base/errors.rb +35 -0
  107. data/lib/convenient_service/rspec/matchers/custom/results/base.rb +73 -12
  108. data/lib/convenient_service/rspec/matchers/custom/singleton_prepend_module.rb +79 -0
  109. data/lib/convenient_service/rspec/matchers/custom.rb +1 -0
  110. data/lib/convenient_service/rspec/matchers/singleton_prepend_module.rb +13 -0
  111. data/lib/convenient_service/rspec/matchers.rb +2 -0
  112. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/concern.rb +85 -0
  113. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize/middleware.rb +27 -0
  114. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/initialize.rb +3 -0
  115. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs/middleware.rb +25 -0
  116. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result/to_kwargs.rb +3 -0
  117. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_have_parent_result.rb +5 -0
  118. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +7 -1
  119. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +4 -0
  120. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/concern.rb +27 -0
  121. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize/middleware.rb +27 -0
  122. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/initialize.rb +3 -0
  123. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs/middleware.rb +25 -0
  124. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step/to_kwargs.rb +3 -0
  125. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_step.rb +5 -0
  126. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
  127. data/lib/convenient_service/service/plugins/has_result_method_steps.rb +0 -2
  128. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +40 -4
  129. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method.rb +3 -0
  130. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb +8 -1
  131. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_direction.rb +3 -0
  132. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_key.rb +8 -1
  133. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_name.rb +9 -5
  134. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/define_method_in_container.rb +2 -2
  135. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/concern/instance_methods.rb +4 -0
  136. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/base.rb +4 -0
  137. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands/define_method_in_container.rb +74 -0
  138. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment/commands.rb +3 -0
  139. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers/reassignment.rb +50 -0
  140. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/callers.rb +1 -0
  141. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values/reassignment.rb +43 -0
  142. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities/values.rb +3 -0
  143. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/entities.rb +1 -0
  144. data/lib/convenient_service/service/plugins/has_result_steps/entities/method/errors.rb +22 -0
  145. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb +39 -3
  146. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result/middleware.rb +23 -0
  147. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/can_have_parent_result.rb +3 -0
  148. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +1 -0
  149. data/lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb +13 -0
  150. data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +18 -4
  151. data/lib/convenient_service/services/run_method_in_organizer.rb +28 -0
  152. data/lib/convenient_service/services/run_own_method_in_organizer.rb +64 -0
  153. data/lib/convenient_service/{service/plugins/has_result_method_steps/services.rb → services.rb} +0 -1
  154. data/lib/convenient_service/support/arguments/null_arguments.rb +28 -0
  155. data/lib/convenient_service/support/arguments.rb +87 -0
  156. data/lib/convenient_service/support/copyable.rb +6 -2
  157. data/lib/convenient_service/support/dependency_container/commands/assert_valid_scope.rb +32 -0
  158. data/lib/convenient_service/support/dependency_container/commands/import_method.rb +13 -23
  159. data/lib/convenient_service/support/dependency_container/commands.rb +1 -0
  160. data/lib/convenient_service/support/dependency_container/constants.rb +4 -2
  161. data/lib/convenient_service/support/dependency_container/entities/method.rb +2 -9
  162. data/lib/convenient_service/support/dependency_container/entities/namespace_collection.rb +0 -9
  163. data/lib/convenient_service/support/dependency_container/errors.rb +26 -1
  164. data/lib/convenient_service/support/dependency_container/export.rb +8 -0
  165. data/lib/convenient_service/support/dependency_container/import.rb +3 -1
  166. data/lib/convenient_service/support/not_passed.rb +3 -1
  167. data/lib/convenient_service/support/version/null_version.rb +7 -0
  168. data/lib/convenient_service/support/version.rb +11 -1
  169. data/lib/convenient_service/support.rb +1 -0
  170. data/lib/convenient_service/utils/object/instance_variable_delete.rb +41 -0
  171. data/lib/convenient_service/utils/object/instance_variable_fetch.rb +4 -0
  172. data/lib/convenient_service/utils/object.rb +9 -0
  173. data/lib/convenient_service/utils/proc/display.rb +43 -0
  174. data/lib/convenient_service/utils/proc.rb +5 -0
  175. data/lib/convenient_service/version.rb +1 -1
  176. data/lib/convenient_service.rb +6 -0
  177. data/logo.png +0 -0
  178. metadata +154 -10
  179. data/lib/convenient_service/service/plugins/has_result_method_steps/errors.rb +0 -23
  180. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +0 -55
  181. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_method_in_organizer.rb +0 -30
  182. data/lib/convenient_service/service/plugins/has_result_method_steps/services/run_own_method_in_organizer.rb +0 -52
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "array/wrap"
4
+
5
+ module ConvenientService
6
+ module Examples
7
+ module Standard
8
+ module RequestParams
9
+ module Utils
10
+ module Array
11
+ class << self
12
+ def wrap(object)
13
+ Wrap.call(object)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module RequestParams
7
+ module Utils
8
+ module HTTP
9
+ module Request
10
+ ##
11
+ # TODO: Specs.
12
+ #
13
+ class ParseBody < Support::Command
14
+ attr_reader :http_string
15
+
16
+ def initialize(http_string:)
17
+ @http_string = http_string
18
+ end
19
+
20
+ ##
21
+ # IMPORTANT: Make sure length is set in `http_string`.
22
+ #
23
+ # - https://stackoverflow.com/a/17599778/12201472
24
+ # - https://github.com/ruby/webrick/blob/v1.7.0/lib/webrick/httprequest.rb
25
+ #
26
+ def call
27
+ webrick_request = ::WEBrick::HTTPRequest.new(::WEBrick::Config::HTTP)
28
+
29
+ webrick_request.parse(::StringIO.new(http_string))
30
+
31
+ webrick_request.body
32
+ rescue ::WEBrick::HTTPStatus::BadRequest
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module RequestParams
7
+ module Utils
8
+ module HTTP
9
+ module Request
10
+ ##
11
+ # TODO: Specs.
12
+ #
13
+ class ParsePath < Support::Command
14
+ attr_reader :http_string
15
+
16
+ def initialize(http_string:)
17
+ @http_string = http_string
18
+ end
19
+
20
+ ##
21
+ # - https://stackoverflow.com/a/17599778/12201472
22
+ # - https://github.com/ruby/webrick/blob/v1.7.0/lib/webrick/httprequest.rb
23
+ #
24
+ def call
25
+ webrick_request = ::WEBrick::HTTPRequest.new(::WEBrick::Config::HTTP)
26
+
27
+ webrick_request.parse(::StringIO.new(http_string))
28
+
29
+ webrick_request.path
30
+ rescue ::WEBrick::HTTPStatus::BadRequest
31
+ nil
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "request/parse_body"
4
+ require_relative "request/parse_path"
5
+
6
+ module ConvenientService
7
+ module Examples
8
+ module Standard
9
+ module RequestParams
10
+ module Utils
11
+ module HTTP
12
+ module Request
13
+ class << self
14
+ def parse_body(http_string)
15
+ ParseBody.call(http_string: http_string)
16
+ end
17
+
18
+ def parse_path(http_string)
19
+ ParsePath.call(http_string: http_string)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "http/request"
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ #
5
+ #
6
+ module ConvenientService
7
+ module Examples
8
+ module Standard
9
+ module RequestParams
10
+ module Utils
11
+ module Integer
12
+ ##
13
+ # TODO: Specs.
14
+ #
15
+ class SafeParse < Support::Command
16
+ attr_reader :object
17
+
18
+ def initialize(object)
19
+ @object = object
20
+ end
21
+
22
+ def call
23
+ ::Kernel.Integer(object, exception: false)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # @internal
5
+ # NOTE: `require_relative "integer/safe_parse"` does NOT work. Why?
6
+ #
7
+ require_relative "integer/safe_parse"
8
+
9
+ module ConvenientService
10
+ module Examples
11
+ module Standard
12
+ module RequestParams
13
+ module Utils
14
+ module Integer
15
+ class << self
16
+ def safe_parse(string)
17
+ SafeParse.call(string)
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
+ ##
4
+ # Tries to parse a JSON string and return the corresponding JSON object (Ruby hash, array, etc).
5
+ # Returns default value when fails to parse (default value is set to `nil` by default).
6
+ #
7
+ # IMPORTANT: `JSON::ParseError` is not the only exception that can be raised by `JSON.parse`.
8
+ # Check this link (`Ctrl + f' for `error'):
9
+ # https://github.com/ruby/ruby/blob/master/ext/json/lib/json.rb
10
+ #
11
+ module ConvenientService
12
+ module Examples
13
+ module Standard
14
+ module RequestParams
15
+ module Utils
16
+ module JSON
17
+ class SafeParse < Support::Command
18
+ attr_reader :json_string, :default_value
19
+
20
+ def initialize(json_string, default_value: nil)
21
+ @json_string = json_string
22
+ @default_value = default_value
23
+ end
24
+
25
+ def call
26
+ return default_value unless json_string.instance_of?(::String)
27
+
28
+ begin
29
+ ::JSON.parse(json_string)
30
+ rescue
31
+ default_value
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "json/safe_parse"
4
+
5
+ module ConvenientService
6
+ module Examples
7
+ module Standard
8
+ module RequestParams
9
+ module Utils
10
+ module JSON
11
+ class << self
12
+ def safe_parse(json_string, default_value: nil)
13
+ SafeParse.call(json_string, default_value: default_value)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ #
5
+ #
6
+ module ConvenientService
7
+ module Examples
8
+ module Standard
9
+ module RequestParams
10
+ module Utils
11
+ module Object
12
+ ##
13
+ # TODO: Specs.
14
+ #
15
+ class Blank < Support::Command
16
+ attr_reader :object
17
+
18
+ def initialize(object)
19
+ @object = object
20
+ end
21
+
22
+ ##
23
+ # https://api.rubyonrails.org/classes/Object.html#method-i-blank-3F
24
+ #
25
+ def call
26
+ object.respond_to?(:empty?) ? !!object.empty? : !object
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ #
5
+ #
6
+ module ConvenientService
7
+ module Examples
8
+ module Standard
9
+ module RequestParams
10
+ module Utils
11
+ module Object
12
+ ##
13
+ # TODO: Specs.
14
+ #
15
+ class Present < Support::Command
16
+ attr_reader :object
17
+
18
+ def initialize(object)
19
+ @object = object
20
+ end
21
+
22
+ def call
23
+ Utils::Object.blank?(object)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "object/blank"
4
+ require_relative "object/present"
5
+
6
+ module ConvenientService
7
+ module Examples
8
+ module Standard
9
+ module RequestParams
10
+ module Utils
11
+ module Object
12
+ class << self
13
+ def blank?(object)
14
+ Blank.call(object)
15
+ end
16
+
17
+ def present?(object)
18
+ Present.call(object)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "utils/array"
4
+ require_relative "utils/http"
5
+ require_relative "utils/integer"
6
+ require_relative "utils/json"
7
+ require_relative "utils/object"
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "request_params/constants"
4
+ require_relative "request_params/entities"
5
+ require_relative "request_params/services"
6
+ require_relative "request_params/utils"
7
+
8
+ ##
9
+ # @since 0.3.0
10
+ #
11
+ # @internal
12
+ # Usage example:
13
+ #
14
+ # http_string =
15
+ # <<~TEXT
16
+ # POST /rules/1000000.json HTTP/1.1
17
+ # User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
18
+ # Host: code-review.com
19
+ # Content-Type: application/json; charset=utf-8
20
+ # Content-Length: 134
21
+ # Accept-Language: en-us
22
+ # Accept-Encoding: gzip, deflate
23
+ # Connection: Keep-Alive
24
+ #
25
+ # {"title":"Avoid error shadowing","description":"Check the official User Docs","tags":["error-shadowing"]}
26
+ # TEXT
27
+ #
28
+ # request = ConvenientService::Examples::Standard::RequestParams::Entities::Request.new(http_string:)
29
+ #
30
+ # ConvenientService::Examples::Standard::RequestParams.prepare(request)
31
+ #
32
+ # - https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
33
+ # - https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome
34
+ # - https://www.tutorialspoint.com/http/http_requests.htm
35
+ #
36
+ module ConvenientService
37
+ module Examples
38
+ module Standard
39
+ module RequestParams
40
+ class << self
41
+ def prepare(request)
42
+ Services::Prepare[request: request]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Arguments
9
+ ##
10
+ # @return [Array]
11
+ #
12
+ # @example Default.
13
+ #
14
+ # hello(*args)
15
+ #
16
+ def create_args
17
+ [:foo, :bar]
18
+ end
19
+
20
+ ##
21
+ # @return [Hash]
22
+ #
23
+ # @example Default.
24
+ #
25
+ # hello(**kwargs)
26
+ #
27
+ def create_kwargs
28
+ {foo: :bar, baz: :qux}
29
+ end
30
+
31
+ ##
32
+ # @return [Hash]
33
+ #
34
+ # @example Default.
35
+ #
36
+ # hello(&block)
37
+ #
38
+ def create_block
39
+ proc { :foo }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # WIP: Factory API is NOT well-thought yet. It will be revisited and completely refactored at any time.
5
+ #
6
+ module ConvenientService
7
+ module Factories
8
+ module Results
9
+ ##
10
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
11
+ #
12
+ # @example Default.
13
+ #
14
+ # class Service
15
+ # include ConvenientService::Standard::Config
16
+ #
17
+ # def result
18
+ # success # `result` is return value
19
+ # end
20
+ # end
21
+ #
22
+ def create_result
23
+ service_class = create_service_class
24
+
25
+ service_class.result
26
+ end
27
+
28
+ ##
29
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
30
+ #
31
+ # @example Default.
32
+ #
33
+ # class Service
34
+ # include ConvenientService::Standard::Config
35
+ #
36
+ # def result
37
+ # success # `result` is return value
38
+ # end
39
+ # end
40
+ #
41
+ def create_result_without_step
42
+ service_class = create_service_class
43
+
44
+ service_class.result
45
+ end
46
+
47
+ ##
48
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
49
+ #
50
+ # @example Default.
51
+ #
52
+ # class Service
53
+ # include ConvenientService::Standard::Config
54
+ #
55
+ # step Step # `result` is return value
56
+ # end
57
+ #
58
+ def create_result_with_step(...)
59
+ create_result_with_service_step(...)
60
+ end
61
+
62
+ ##
63
+ # @param service_step [Class]
64
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
65
+ #
66
+ # @example Default.
67
+ #
68
+ # class Service
69
+ # include ConvenientService::Standard::Config
70
+ #
71
+ # step Step # `result` is return value
72
+ # end
73
+ #
74
+ # @example When `service_step` is passed.
75
+ #
76
+ # class Service
77
+ # include ConvenientService::Standard::Config
78
+ #
79
+ # step service_step # `result` is return value
80
+ # end
81
+ #
82
+ def create_result_with_service_step(service_step: Support::NOT_PASSED)
83
+ service_step_class = (service_step == Support::NOT_PASSED) ? create_service_step_class : service_step
84
+
85
+ service_class = create_service_class(steps: [service_step_class])
86
+
87
+ service_class.result
88
+ end
89
+
90
+ ##
91
+ # @param method_step [Symbol]
92
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
93
+ #
94
+ # @example Default.
95
+ #
96
+ # class Service
97
+ # include ConvenientService::Standard::Config
98
+ #
99
+ # step :validate # `result` is return value
100
+ # end
101
+ #
102
+ # @example When `method_step` is passed.
103
+ #
104
+ # class Service
105
+ # include ConvenientService::Standard::Config
106
+ #
107
+ # step method_step # `result` is return value
108
+ # end
109
+ #
110
+ def create_result_with_method_step(method_step: Support::NOT_PASSED)
111
+ method_step = (method_step == Support::NOT_PASSED) ? create_method_step : method_step
112
+
113
+ service_class = create_service_class(steps: [method_step])
114
+
115
+ service_class.result
116
+ end
117
+
118
+ ##
119
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
120
+ #
121
+ # @example Default.
122
+ #
123
+ # class Service
124
+ # include ConvenientService::Standard::Config
125
+ #
126
+ # step :result # `result` is return value
127
+ # end
128
+ #
129
+ def create_result_with_result_method_step
130
+ service_class = create_service_class(steps: [:result])
131
+
132
+ service_class.result
133
+ end
134
+
135
+ ##
136
+ # @return [Hash]
137
+ #
138
+ # @example Default.
139
+ #
140
+ # {
141
+ # service: result.service,
142
+ # status: :success,
143
+ # data: {foo: :bar},
144
+ # message: "",
145
+ # code: :default_success
146
+ # }
147
+ #
148
+ def create_result_attributes
149
+ create_result.jsend_attributes.to_h
150
+ end
151
+
152
+ ##
153
+ # @return [Hash]
154
+ #
155
+ # @example Default.
156
+ #
157
+ # {
158
+ # service: result.service,
159
+ # status: :success,
160
+ # data: {foo: :bar},
161
+ # message: "",
162
+ # code: :default_success,
163
+ # parent: result.parent
164
+ # }
165
+ #
166
+ def create_result_attributes_with_parent(parent: Support::NOT_PASSED)
167
+ parent = (parent == Support::NOT_PASSED) ? create_result_parent : parent
168
+
169
+ result_attributes = create_result_attributes
170
+
171
+ result_attributes.merge(parent: parent)
172
+ end
173
+
174
+ ##
175
+ # @return [Hash]
176
+ #
177
+ # @example Default.
178
+ #
179
+ # {
180
+ # service: result.service,
181
+ # status: :success,
182
+ # data: {foo: :bar},
183
+ # message: "",
184
+ # code: :default_success,
185
+ # step: result.step
186
+ # }
187
+ #
188
+ def create_result_attributes_with_step(step: Support::NOT_PASSED)
189
+ step = (step == Support::NOT_PASSED) ? create_result_step : step
190
+
191
+ result_attributes = create_result_attributes
192
+
193
+ result_attributes.merge(step: step)
194
+ end
195
+
196
+ ##
197
+ # @return [ConvenientService::Service::Plugins::HasResult::Entities::Result]
198
+ #
199
+ # @example Default.
200
+ #
201
+ # class Service
202
+ # include ConvenientService::Standard::Config
203
+ #
204
+ # def result
205
+ # success # `result_parent` is return value
206
+ # end
207
+ # end
208
+ #
209
+ def create_result_parent
210
+ create_result
211
+ end
212
+ end
213
+ end
214
+ end