nshki / chusaku

Annotate your Rails controllers with route info.
https://rubygems.org/gems/chusaku
MIT License
87 stars 4 forks source link

Annotate controllers in Rails engines and packs #48

Open aburgel opened 1 month ago

aburgel commented 1 month ago

This is a draft. I still have to get the tests updated and write more tests, but I wanted to get some feedback before doing so.

I approached this in a different way from the current implementation.

  1. It starts similarly by gathering all the routes, to which I added following routes of any mounted engines.
  2. Then instead of iterating through the controllers provided by the controller pattern, I iterated through the routes and then loaded the corresponding controller class.
  3. From there I got the source location of controller, and added the annotations but only if the source location matched the controller pattern.

It's possible with Zeitwerk (and probably other mechanisms) for the controller name and path to not line up exactly, so with this approach you don't need to make any assumptions.

Please let me know what you think and if it looks good, I can add and update the tests.

Fixes #47

nshki commented 1 month ago

🙇🏻 Thanks for opening this draft PR! Just wanted to acknowledge that I saw this but haven't had the time to look over it quite yet. I'll try to get dedicated time soon to consider your direction here and will provide feedback.