项目作者: serradura

项目描述 :
Rails (API) app that shows different kinds of architecture (one per commit), and in the last one, how to use the Micro::Case gem to handle the application business logic.
高级语言: Ruby
项目地址: git://github.com/serradura/from-fat-controllers-to-use-cases.git


From fat controllers to use cases

Rails (API) app that shows different kinds of architecture (one per commit), and in the last one, how to use the Micro::Case gem to handle the application business logic.

Instructions to run this application

  • Ruby version: 2.6.5
  • System dependencies: sqlite3
  • Configuration and database creation: bin/setup
  • How to run the test suite: bin/rails test

The different kinds of architecture (project versions)

Version Description Rubycritic Score
1 Fat controller 91.53
2 Fat model, skinny controller 87.45
3 Concerns 89.25
4 Service objects 92.55
4.1 Service objects - Inheritance 92.93
4.2 Service objects - Inheritance overusing 93.15
5 Interactors 96.36
6 Domain objects 94.71
7 Use cases (Micro::Case) 94.97
7.1 Use cases - Dryer version 95.24
7.2 Use cases- Improving the SRP 95.11

Hint: in any of the versions above, use bin/rails rubycritic to see the full report result.

Extra: How to list all the use cases?

Use the use_cases task. e.g:

  1. bin/rails use_cases
  2. # Lines:
  3. # 11 ./app/models/user/register/step/serialize_as_json.rb
  4. # 12 ./app/models/user/register/step/validate_password.rb
  5. # 17 ./app/models/user/register/step/create_record.rb
  6. # 19 ./app/models/user/register/step/normalize_params.rb
  7. # 10 ./app/models/user/register/flow.rb
  8. # 18 ./app/models/todo/list/add_item.rb
  9. # 16 ./app/models/todo/list/complete_item.rb
  10. # 14 ./app/models/todo/list/delete_item.rb
  11. # 12 ./app/models/todo/list/fetch_items.rb
  12. # 14 ./app/models/todo/list/find_item.rb
  13. # 19 ./app/models/todo/list/update_item.rb
  14. # 16 ./app/models/todo/list/activate_item.rb
  15. # 21 ./app/models/todo/serialize.rb
  16. # 199 total
  17. #
  18. # Files: 13

Note: This task will only be available in the branches with use cases (v7, v7.1, v7.2).