convenient_service 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gem_release.yml +0 -12
  3. data/.github/issue_template.md +35 -0
  4. data/.github/pull_request_template.md +31 -0
  5. data/.github/workflows/cd.yml +15 -2
  6. data/CHANGELOG.md +18 -0
  7. data/README.md +12 -3
  8. data/ROADMAP.md +19 -8
  9. data/Taskfile.yml +2 -10
  10. data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -2
  11. data/lib/convenient_service/common/plugins/caches_return_value.rb +0 -1
  12. data/lib/convenient_service/common/plugins/has_constructor/concern.rb +13 -0
  13. data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +27 -0
  14. data/lib/convenient_service/common/plugins/has_constructor_without_initialize.rb +3 -0
  15. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +8 -4
  16. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +0 -1
  17. data/lib/convenient_service/common/plugins.rb +1 -0
  18. data/lib/convenient_service/configs/standard.rb +16 -0
  19. data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +0 -2
  20. data/lib/convenient_service/dependencies.rb +1 -0
  21. data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
  22. data/lib/convenient_service/examples/rails/gemfile.rb +5 -4
  23. data/lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb +42 -0
  24. data/lib/convenient_service/examples/standard/cowsay/services/build_cow.rb +38 -0
  25. data/lib/convenient_service/examples/standard/cowsay/services/print.rb +32 -0
  26. data/lib/convenient_service/examples/standard/cowsay/services.rb +5 -0
  27. data/lib/convenient_service/examples/standard/cowsay.rb +24 -0
  28. data/lib/convenient_service/examples/standard/gemfile/services/format.rb +2 -0
  29. data/lib/convenient_service/examples/standard/gemfile.rb +5 -4
  30. data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +96 -7
  31. data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +44 -8
  32. data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +11 -9
  33. data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
  34. data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +6 -0
  35. data/lib/convenient_service/service/plugins/aliases.rb +1 -0
  36. data/lib/convenient_service/service/plugins/has_inspect/concern.rb +23 -0
  37. data/lib/convenient_service/service/plugins/has_inspect.rb +3 -0
  38. data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +10 -0
  39. data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +23 -14
  40. data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +17 -1
  41. data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +4 -3
  42. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb +31 -0
  43. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb +3 -0
  44. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb +37 -0
  45. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +3 -0
  46. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +115 -0
  47. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +27 -0
  48. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb +34 -0
  49. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +49 -0
  50. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +32 -0
  51. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +49 -0
  52. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +34 -0
  53. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +45 -0
  54. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +34 -0
  55. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +73 -0
  56. data/lib/convenient_service/service/plugins/has_result/entities/result/{entities.rb → plugins/has_jsend_status_and_attributes/entities.rb} +0 -0
  57. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb +29 -0
  58. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb +31 -0
  59. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb +21 -0
  60. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +3 -0
  61. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +8 -0
  62. data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
  63. data/lib/convenient_service/service/plugins/has_result/entities/result.rb +0 -4
  64. data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -1
  65. data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +30 -4
  66. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +63 -0
  67. data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb +3 -0
  68. data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +2 -1
  69. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb +31 -0
  70. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb +3 -0
  71. data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +3 -0
  72. data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +1 -0
  73. data/lib/convenient_service/service/plugins.rb +2 -0
  74. data/lib/convenient_service/support/cache/key.rb +100 -0
  75. data/lib/convenient_service/support/cache.rb +131 -0
  76. data/lib/convenient_service/support/copyable.rb +3 -2
  77. data/lib/convenient_service/support/delegate.rb +3 -2
  78. data/lib/convenient_service/support.rb +1 -0
  79. data/lib/convenient_service/version.rb +1 -1
  80. data/logo.png +0 -0
  81. metadata +40 -21
  82. data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +0 -79
  83. data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +0 -3
  84. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +0 -81
  85. data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +0 -3
  86. data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +0 -33
  87. data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +0 -3
  88. data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +0 -64
  89. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +0 -30
  90. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +0 -45
  91. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +0 -28
  92. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +0 -45
  93. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +0 -30
  94. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +0 -41
  95. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +0 -30
  96. data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +0 -69
  97. data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +0 -25
  98. data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +0 -17
  99. data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ac75a9e4491384ec69ea4ddf3b7e9c4b9fc652dda2ec28236d0625d684605a2
4
- data.tar.gz: a76819b97f23ef9d66185757832cb3be6c8b703cbfbe39fa8704be59c2af936d
3
+ metadata.gz: 03335557e59a7d6c469fe20e478efb1d7f9563d7651b5e0761e61d820e7515e6
4
+ data.tar.gz: 055c3cfaa2b176689bf8cc105d649a40779788279c89bd1f5a6bdfde8d7994c1
5
5
  SHA512:
6
- metadata.gz: 8da7165d9eee47a3f978db542c7eaf77b6b80d8a2c27d885ce032b8433bae881d2c7c345923c676c38b1b1d30ad5aef9231c962ae282d0392f7278d768e8d9d6
7
- data.tar.gz: e64a25c3a7513b2c2cf028a11c6a1ee692d6ad01c31ebd053d32e44c980bfddab9e77c2a1d7ca5fa529e4458eea6dae026b3f01bb743159045d6874e02757a47
6
+ metadata.gz: f9f55f6baab2736bcbb8661a55bb494bdfb1f7e000a87b3c7c78f326b417e44bcd69cccb992b54435ec10ce919afc2e3a7cd73695858025fa241aff609b9882c
7
+ data.tar.gz: 72778dcdb0df0003b3c9b13a266af24a9c8de4150ed7d048887bd5007b223c88ce34c9494c186c5ac49ba0102ca5bd31858e37d55698fe1cfb49fe22dd6ed6e7
data/.gem_release.yml CHANGED
@@ -1,17 +1,5 @@
1
1
  quiet: false
2
2
 
3
- ##
4
- # NOTE: `bump` options.
5
- # https://github.com/svenfuchs/gem-release#gem-bump
6
- #
7
- bump:
8
- file: ./lib/convenient_service/version.rb
9
- message: 🎉 🎉 🎉 Release %{version} 🎉 🎉 🎉
10
- recurse: false
11
- release: true
12
- sign: true
13
- tag: true
14
-
15
3
  ##
16
4
  # NOTE: `release` options.
17
5
  # https://github.com/svenfuchs/gem-release#gem-release
@@ -0,0 +1,35 @@
1
+ ## What is the issue?
2
+ <!--- Briefly describe the problem -->
3
+
4
+ -
5
+
6
+ ## When it happens? How to reproduce it?
7
+ <!--- Tell us how to reproduce the problem. You can write a step-by-step guide, for example -->
8
+
9
+ -
10
+
11
+ ## Where it happens?
12
+ <!--- Point to the file/loc which causes inconsistent behaviour -->
13
+
14
+ -
15
+
16
+ ## How big is the damage from it?
17
+
18
+ -
19
+
20
+ ## Why it happens?
21
+
22
+ -
23
+
24
+ ## What can be done to resolve it?
25
+
26
+ -
27
+
28
+ ## What is the complexity of a possible fix?
29
+
30
+ -
31
+
32
+ ## Notes
33
+ <!--- Additional info, links, screenshots, actually anything that helps to recreate the way of thoughts (optional). -->
34
+
35
+ -
@@ -0,0 +1,31 @@
1
+ ## What was done as a part of this PR?
2
+ <!--- Describe your changes -->
3
+
4
+ -
5
+
6
+ ## Why it was done?
7
+ <!--- Why is this change required? Does it improve something? What problem does it solve? -->
8
+ <!--- If it fixes an open issue, please link to the issue here. -->
9
+
10
+ -
11
+
12
+ ## How it was done?
13
+ <!--- Useful when a solution is not obvious (seems too extraordinary or too heavy) for a team you work with (optional). -->
14
+
15
+ -
16
+
17
+ ## How to test?
18
+
19
+ - `task rspec -- corresponding_spec.rb`
20
+ - [Development: Local Development#tests](https://github.com/marian13/convenient_service/wiki/Development:-Local-Development#tests).
21
+
22
+ ## Notes
23
+ <!--- Additional info, links, screenshots, actually anything that helps to recreate the way of thoughts (optional). -->
24
+
25
+ -
26
+
27
+ ## Checklist:
28
+
29
+ - [ ] I have performed a self-review of my code.
30
+ - [ ] I have added/adjusted tests that prove my fix is effective or that my feature works.
31
+ - [ ] CI is green.
@@ -22,9 +22,9 @@ on:
22
22
  - main
23
23
 
24
24
  jobs:
25
- deploy:
25
+ deploy_api_docs:
26
26
  runs-on: ubuntu-20.04
27
- name: Deploy
27
+ name: Deploy API Docs
28
28
  steps:
29
29
  - uses: actions/checkout@v2
30
30
  - name: Set up Ruby
@@ -52,3 +52,16 @@ jobs:
52
52
  with:
53
53
  github_token: ${{ secrets.GITHUB_TOKEN }}
54
54
  publish_dir: ./docs
55
+
56
+ create_github_release:
57
+ runs-on: ubuntu-20.04
58
+ name: Create GitHub Release PR
59
+ steps:
60
+ - uses: google-github-actions/release-please-action@v3
61
+ with:
62
+ changelog-path: CHANGELOG.md
63
+ default-branch: main
64
+ include-v-in-tag: true
65
+ package-name: convenient_service
66
+ release-type: ruby
67
+ version-file: lib/convenient_service/version.rb
data/CHANGELOG.md CHANGED
@@ -1 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://github.com/marian13/convenient_service/compare/v0.1.0...v0.2.0) (2022-11-26)
4
+
5
+
6
+ ### Features
7
+
8
+ * **be_success:** add without_data chaining ([e1c7a7e](https://github.com/marian13/convenient_service/commit/e1c7a7e534b4c8c112b343a3318177d69f7ad06d))
9
+ * **has_constructor_without_initialize:** introduce .create_without_initialize ([b0835aa](https://github.com/marian13/convenient_service/commit/b0835aaae46820b47ecc57887613acd8599c1908))
10
+ * **has_constructor:** introduce .create ([2cc450b](https://github.com/marian13/convenient_service/commit/2cc450bd529596ac8e2fda3d26c2e0b1d4fad959))
11
+ * **has_inspect:** indroduce inspect for Service and Result ([c3815c8](https://github.com/marian13/convenient_service/commit/c3815c8d25f47d8f2457ccfbad8660a930e32da1))
12
+ * **has_inspect:** introduce HasInspect for Step ([6a6ada7](https://github.com/marian13/convenient_service/commit/6a6ada73962ea96f5e9c40d62e87d91a1e09b961))
13
+ * **has_inspect:** introduce inspect for Service and Result ([7c9fe0e](https://github.com/marian13/convenient_service/commit/7c9fe0e4a7aedfcaff1e717f99a934d2fab4c03b))
14
+ * **has_result_status_check_short_syntax:** add ability to use short bool result check ([14909c5](https://github.com/marian13/convenient_service/commit/14909c584164a2bd130f788fa48e76edd3c7a758))
15
+ * **standard:** use HasConstructorWithoutInitialize ([b16232c](https://github.com/marian13/convenient_service/commit/b16232c88fe75028531cd7e834fb59fece49d122))
16
+ * **wrap_method:** add ability to reset wrapped method ([ae01aa8](https://github.com/marian13/convenient_service/commit/ae01aa825dcf0d06b2abdc693331dccb65d95d6b))
17
+
18
+
1
19
  ## 0.1.0
data/README.md CHANGED
@@ -29,8 +29,6 @@
29
29
 
30
30
  <!-- general_description:start -->
31
31
  Yet another approach to revisit the service object pattern, but this time focusing on the unique, opinionated features.
32
-
33
- \* Logo is downloaded from [CuteWallpaper.org](https://cutewallpaper.org/24/cartoon-diamond-png/2703010921.html). It will be replaced later.
34
32
  <!-- general_description:end -->
35
33
 
36
34
  <!-- warning:start -->
@@ -47,9 +45,20 @@ This library is under heavy development. Public API may be subject to change. Th
47
45
 
48
46
  - Have a look at [Convenient Service Development Wiki](https://github.com/marian13/convenient_service/wiki) if you consider making a contribution.
49
47
 
50
- ---
48
+ - [API docs](https://marian13.github.io/convenient_service/).
49
+
51
50
  <!-- documentation:end -->
52
51
 
52
+ ## Links
53
+
54
+ <!-- links:start -->
55
+ - [RubyGems](https://rubygems.org/gems/convenient_service).
56
+
57
+ - [Official User Docs Source](https://github.com/marian13/convenient_service_docs).
58
+ <!-- links:end -->
59
+
60
+ ---
61
+
53
62
  <!-- author:start -->
54
63
  Copyright (c) 2022 [Marian Kostyk](http://mariankostyk.com).
55
64
  <!-- author:end -->
data/ROADMAP.md CHANGED
@@ -4,11 +4,11 @@
4
4
  | - | - | - | - |
5
5
  | High | ✅ | 100% coverage of `Core` | |
6
6
  | Medium | 🚧 | Type signatures for the whole codebase ([Yard @param, @overload, @return](https://rubydoc.info/gems/yard/file/docs/Tags.md#taglist)) | |
7
- | Medium | 🚧 | `Service.success?` shortcut for `Service.result.success?` | |
8
- | Medium | 🚧 | Release `v0.1.0` with a warning that lib is still under heavy development | |
7
+ | Medium | | `Service.success?` shortcut for `Service.result.success?` | |
8
+ | Medium | | Release `v0.1.0` with a warning that lib is still under heavy development | |
9
9
  | Medium | 🚧 | [Active Record transaction](https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html) examples | |
10
+ | Medium | 🚧 | [Rails Current Attributes integration](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html) to cache repeated results | |
10
11
  | Low | 🚧 | [Capybara](https://github.com/teamcapybara/capybara) examples | |
11
- | Low | 🚧 | [Thread.current](https://ruby-doc.org/core-3.1.2/Thread.html#method-c-current) to cache repetable nested steps during an organizer invocation | |
12
12
  | Medium | 🚧 | Inline step sequence | |
13
13
  | High | 🚧 | Move callbacks to internals | |
14
14
  | Low | 🚧 | Create an example of `id_or_record` [attribute](https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html) |
@@ -17,7 +17,7 @@
17
17
  | High | ✅ | `respond_to_missing?` | [ConvenientService::Core::ClassMethods#respond_to_missing?](https://github.com/marian13/convenient_service/blob/main/lib/convenient_service/core/class_methods.rb#L105), [ConvenientService::Core::InstanceMethods#respond_to_missing?](https://github.com/marian13/convenient_service/blob/main/lib/convenient_service/core/instance_methods.rb#L30) |
18
18
  | High | ⏳ | Custom matcher to track `ConvenientService::Logger` messages | |
19
19
  | Medium | 🚧 | Remove `respond_to?` from `Copyable` | Investigate before making any decision |
20
- | High | 🚧 | Unified `inspect` | |
20
+ | High | 🚧 | Unified `inspect` | Remove `internals` from inspect, ivars wrapperd by double underscore |
21
21
  | High | ✅ | Remove race condition for `method_missing` | https://github.com/marian13/convenient_service/pull/5 |
22
22
  | High | ✅ | Remove incompatiility of [Module#include](https://gist.github.com/marian13/9c25041f835564e945d978839097d419) | https://github.com/marian13/convenient_service/pull/3 |
23
23
  | Medium | ✅ | Split `Utils` specs into separate files | [convenient_service/spec/lib/convenient_service/utils](https://github.com/marian13/convenient_service/tree/main/spec/lib/convenient_service/utils) |
@@ -25,7 +25,6 @@
25
25
  | Medium | ✅ | Rename `Utils::Module.find_own_const` to `Utils::Module.get_own_const` | [ConvenientService::Utils::Module::GetOwnConst](https://github.com/marian13/convenient_service/blob/main/lib/convenient_service/utils/module/get_own_const.rb) |
26
26
  | Medium | 🚧 | Mark `@api private` methods, classes | [YARD Tags](https://www.rubydoc.info/gems/yard/file/docs/Tags.md) |
27
27
  | Medium | ✅ | A way to check if block has one required positional argument | [#proc_has_one_positional_argument?](https://github.com/marian13/convenient_service/blob/main/lib/convenient_service/utils/proc/exec_config.rb#L96) |
28
- | Medium | 🚧 | Factories for POROs in specs | |
29
28
  | Low | 🚧 | Define method middleware caller with visibility | |
30
29
  | Low | 🚧 | Dependency containers to remove high coupling | |
31
30
  | Low | 🚧 | Measure performance | |
@@ -33,9 +32,21 @@
33
32
  | High | 🚧 | Optimize `stack.dup` in `MethodMiddlewares#call` | Core v3 |
34
33
  | Medium | 🚧 | Make a decision of what to do with `printable_block` in custom RSpec matchers | |
35
34
  | Medium | 🚧 | User-friendly exception messages | |
36
- | High | 🚧 | Factories for POROs ❗❗❗ | |
35
+ | High | 🚧 | Factories for POROs in specs ❗❗❗ | Start with `result_class`, `class self::Result`, `service_class`, `step_class`, `organizer_class` |
37
36
  | High | 🚧 | Resolve warning during specs | |
38
37
  | Medium | 🚧 | Consider to change/rewrite `delegate` backend to minify its interface | |
39
- | Medium | 🚧 | Same order of attr macros, delegators, initialize, class methods, attr methods, queries, actions, to_*, comparison, inspect | |
40
- | Medium | 🚧 | Move `Cache` to `Support` | |
38
+ | Medium | 🚧 | Same order of attr macros, delegators, initialize, class methods, attr methods, queries, actions, `to_*`, comparison, inspect | |
39
+ | Medium | | Move `Cache` to `Support` | |
41
40
  | Medium | 🚧 | Statically specify plugin dependencies | |
41
+ | Medium | 🚧 | Statically specify plugin entity types | |
42
+ | Medium | 🚧 | Consider to create `ComparableProc` descendant from `Proc` | To abstract away `block&.source_location != other.block&.source_location` |
43
+ | Medium | 🚧 | Consider to use `Struct` as key in `Support::Cache` | To hide overriden [eql?](https://github.com/marian13/convenient_service/blob/v0.1.0/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb#L60) |
44
+ | High | 🚧 | `included_once` for `Support::Concern` |
45
+ | Medium | 🚧 | Custom YARD type for service instance, service class as return values |
46
+ | Medium | 🚧 | Heredoc for error messages |
47
+ | Medium | 🚧 | Specs for `be_success`, `be_error`, `be_failure` matchers | |
48
+ | Low | 🚧 | [Receive Counts](https://relishapp.com/rspec/rspec-mocks/docs/setting-constraints/receive-counts) for `delegate_to` | |
49
+ | Low | 🚧 | Prefer versioning instead of modification plugin | |
50
+ | Low | 🚧 | Consider to move `__steps__` and `__callbacks__` to `internals_class` | Benefit? |
51
+
52
+ Search for `TODO`s in the codebase for more tasks.
data/Taskfile.yml CHANGED
@@ -194,17 +194,9 @@ tasks:
194
194
  - bundle exec rake playground
195
195
  interactive: true
196
196
 
197
- release:major:
197
+ release:
198
198
  cmds:
199
- - gem bump convenient_service --version major
200
-
201
- release:minor:
202
- cmds:
203
- - gem bump convenient_service --version minor
204
-
205
- release:patch:
206
- cmds:
207
- - gem bump convenient_service --version patch
199
+ - gem release
208
200
 
209
201
  rspec:
210
202
  cmds:
@@ -5,10 +5,25 @@ module ConvenientService
5
5
  module Plugins
6
6
  module CachesReturnValue
7
7
  class Middleware < Core::MethodChainMiddleware
8
+ ##
9
+ # @param args [Array]
10
+ # @param kwargs [Hash]
11
+ # @param block [Proc]
12
+ # @return [Object] Can be any type.
13
+ #
8
14
  def next(*args, **kwargs, &block)
9
- key = Entities::Key.new(method: method, args: args, kwargs: kwargs, block: block)
15
+ key = cache.keygen(:return_values, method, *args, **kwargs, &block)
10
16
 
11
- entity.internals.cache.fetch(key) { chain.next(*args, **kwargs, &block) }
17
+ cache.fetch(key) { chain.next(*args, **kwargs, &block) }
18
+ end
19
+
20
+ private
21
+
22
+ ##
23
+ # @return [ConvenientService::Support::Cache]
24
+ #
25
+ def cache
26
+ @cache ||= entity.internals.cache
12
27
  end
13
28
  end
14
29
  end
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "caches_return_value/entities"
4
3
  require_relative "caches_return_value/middleware"
@@ -8,9 +8,22 @@ module ConvenientService
8
8
  include Support::Concern
9
9
 
10
10
  instance_methods do
11
+ ##
12
+ # @return [void]
13
+ #
11
14
  def initialize(...)
12
15
  end
13
16
  end
17
+
18
+ class_methods do
19
+ ##
20
+ # @return [Object]
21
+ # @since 0.2.0
22
+ #
23
+ def create(...)
24
+ new(...)
25
+ end
26
+ end
14
27
  end
15
28
  end
16
29
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Common
5
+ module Plugins
6
+ module HasConstructorWithoutInitialize
7
+ module Concern
8
+ include Support::Concern
9
+
10
+ class_methods do
11
+ ##
12
+ # @return [Object]
13
+ # @since 0.2.0
14
+ #
15
+ # @internal
16
+ # - https://ruby-doc.org/core-2.5.0/Class.html#method-i-allocate
17
+ # - https://frontdeveloper.pl/2018/11/ruby-allocate-method/
18
+ #
19
+ def create_without_initialize
20
+ allocate
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "has_constructor_without_initialize/concern"
@@ -7,16 +7,20 @@ module ConvenientService
7
7
  module Entities
8
8
  class Internals
9
9
  module Plugins
10
+ ##
11
+ # @internal
12
+ # TODO: Consider to refactor into common plugin?
13
+ #
10
14
  module HasCache
11
- ##
12
- # TODO: Specs.
13
- #
14
15
  module Concern
15
16
  include Support::Concern
16
17
 
17
18
  instance_methods do
19
+ ##
20
+ # @return [ConvenientService::Support::Cache]
21
+ #
18
22
  def cache
19
- @cache ||= Entities::Cache.new
23
+ @cache ||= Support::Cache.new
20
24
  end
21
25
  end
22
26
  end
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "has_cache/concern"
4
- require_relative "has_cache/entities"
@@ -11,6 +11,7 @@ require_relative "plugins/can_be_copied"
11
11
  require_relative "plugins/has_around_callbacks"
12
12
  require_relative "plugins/has_callbacks"
13
13
  require_relative "plugins/has_constructor"
14
+ require_relative "plugins/has_constructor_without_initialize"
14
15
  require_relative "plugins/has_internals"
15
16
 
16
17
  require_relative "plugins/aliases"
@@ -20,6 +20,7 @@ module ConvenientService
20
20
  concerns do
21
21
  use Plugins::Common::HasInternals::Concern
22
22
  use Plugins::Common::HasConstructor::Concern
23
+ use Plugins::Common::HasConstructorWithoutInitialize::Concern
23
24
 
24
25
  use Plugins::Common::CachesConstructorParams::Concern
25
26
  use Plugins::Common::CanBeCopied::Concern
@@ -27,10 +28,12 @@ module ConvenientService
27
28
  use Plugins::Service::HasResultShortSyntax::Concern
28
29
  use Plugins::Service::HasResultSteps::Concern
29
30
  use Plugins::Service::CanRecalculateResult::Concern
31
+ use Plugins::Service::HasResultStatusCheckShortSyntax::Concern
30
32
 
31
33
  use Plugins::Common::HasCallbacks::Concern
32
34
  use Plugins::Common::HasAroundCallbacks::Concern
33
35
 
36
+ use Plugins::Service::HasInspect::Concern
34
37
  ##
35
38
  # NOTE: Optional plugins.
36
39
  # TODO: Specs.
@@ -97,9 +100,20 @@ module ConvenientService
97
100
 
98
101
  concerns do
99
102
  use Plugins::Common::HasInternals::Concern
103
+ use Plugins::Common::HasConstructor::Concern
104
+
105
+ use Plugins::Result::HasJsendStatusAndAttributes::Concern
100
106
 
101
107
  use Plugins::Result::HasResultShortSyntax::Concern
102
108
  use Plugins::Result::CanRecalculateResult::Concern
109
+
110
+ use Plugins::Result::HasInspect::Concern
111
+ end
112
+
113
+ middlewares :initialize do
114
+ use Plugins::Common::NormalizesEnv::Middleware
115
+
116
+ use Plugins::Result::HasJsendStatusAndAttributes::Middleware
103
117
  end
104
118
 
105
119
  middlewares :success? do
@@ -170,6 +184,8 @@ module ConvenientService
170
184
 
171
185
  concerns do
172
186
  use Plugins::Common::HasInternals::Concern
187
+
188
+ use Plugins::Step::HasInspect::Concern
173
189
  end
174
190
 
175
191
  middlewares :result do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # frozen_string_literal: true
4
-
5
3
  module ConvenientService
6
4
  module Core
7
5
  module Entities
@@ -102,6 +102,7 @@ module ConvenientService
102
102
  def require_standard_examples
103
103
  require "progressbar"
104
104
 
105
+ require_relative "examples/standard/cowsay"
105
106
  require_relative "examples/standard/gemfile"
106
107
  end
107
108
 
@@ -4,17 +4,18 @@ require_relative "gemfile/dry_service"
4
4
  require_relative "gemfile/services"
5
5
 
6
6
  ##
7
- # Usage example:
7
+ # @internal
8
+ # Usage example:
8
9
  #
9
- # result = ConvenientService::Examples::Dry::Gemfile.format(path: "Gemfile")
10
- # result = ConvenientService::Examples::Dry::Gemfile.format(path: "spec/cli/gemfile/format/fixtures/Gemfile")
10
+ # result = ConvenientService::Examples::Dry::Gemfile.format("Gemfile")
11
+ # result = ConvenientService::Examples::Dry::Gemfile.format("spec/cli/gemfile/format/fixtures/Gemfile")
11
12
  #
12
13
  module ConvenientService
13
14
  module Examples
14
15
  module Dry
15
16
  module Gemfile
16
17
  class << self
17
- def format
18
+ def format(path)
18
19
  Services::Format[path: path]
19
20
  end
20
21
  end
@@ -4,17 +4,18 @@ require_relative "gemfile/rails_service"
4
4
  require_relative "gemfile/services"
5
5
 
6
6
  ##
7
- # Usage example:
7
+ # @internal
8
+ # Usage example:
8
9
  #
9
- # result = ConvenientService::Examples::Rails::Gemfile.format(path: "Gemfile")
10
- # result = ConvenientService::Examples::Rails::Gemfile.format(path: "spec/cli/gemfile/format/fixtures/Gemfile")
10
+ # result = ConvenientService::Examples::Rails::Gemfile.format("Gemfile")
11
+ # result = ConvenientService::Examples::Rails::Gemfile.format("spec/cli/gemfile/format/fixtures/Gemfile")
11
12
  #
12
13
  module ConvenientService
13
14
  module Examples
14
15
  module Rails
15
16
  module Gemfile
16
17
  class << self
17
- def format
18
+ def format(path)
18
19
  Services::Format[path: path]
19
20
  end
20
21
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module Cowsay
7
+ module Services
8
+ class BuildCloud
9
+ include ConvenientService::Standard::Config
10
+
11
+ attr_reader :text
12
+
13
+ def initialize(text: "Hello World!")
14
+ @text = text
15
+ end
16
+
17
+ def result
18
+ success(cloud: cloud)
19
+ end
20
+
21
+ private
22
+
23
+ ##
24
+ # Copied with ❤️ from https://github.com/gaborbata/rosetta-cow
25
+ #
26
+ def cloud
27
+ <<~HEREDOC
28
+ #{border(text, "_")}
29
+ < #{text} >
30
+ #{border(text, "-")}
31
+ HEREDOC
32
+ end
33
+
34
+ def border(text, char)
35
+ char * (text.length + 2)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module Cowsay
7
+ module Services
8
+ class BuildCow
9
+ include ConvenientService::Standard::Config
10
+
11
+ def result
12
+ success(cow: cow)
13
+ end
14
+
15
+ private
16
+
17
+ ##
18
+ # Copied with ❤️ from https://github.com/gaborbata/rosetta-cow
19
+ #
20
+ def cow
21
+ <<~'HEREDOC'.split("\n").map { |line| offset(line) }.join("\n")
22
+ \ ^__^
23
+ \ (oo)\_______
24
+ (__)\ )\/\
25
+ ||----w |
26
+ || ||
27
+ HEREDOC
28
+ end
29
+
30
+ def offset(line)
31
+ " " * 10 + line
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConvenientService
4
+ module Examples
5
+ module Standard
6
+ module Cowsay
7
+ module Services
8
+ class Print
9
+ include ConvenientService::Standard::Config
10
+
11
+ attr_reader :text, :out
12
+
13
+ step Services::BuildCloud, in: :text, out: :cloud
14
+ step Services::BuildCow, out: :cow
15
+ step :result
16
+
17
+ def initialize(text: "Hello World!", out: $stdout)
18
+ @text = text
19
+ @out = out
20
+ end
21
+
22
+ def result
23
+ out.puts cloud + cow
24
+
25
+ success
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "services/build_cloud"
4
+ require_relative "services/build_cow"
5
+ require_relative "services/print"
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cowsay/services"
4
+
5
+ ##
6
+ # @internal
7
+ # Usage examples:
8
+ #
9
+ # result = ConvenientService::Examples::Standard::Cowsay.print("Hello")
10
+ # result = ConvenientService::Examples::Standard::Cowsay.print("Hi")
11
+ #
12
+ module ConvenientService
13
+ module Examples
14
+ module Standard
15
+ module Cowsay
16
+ class << self
17
+ def print(text = "Hello World!", out: $stdout)
18
+ Services::Print[text: text, out: out]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end