hanami / router

Ruby/Rack HTTP router
http://hanamirb.org
MIT License
362 stars 92 forks source link

Extract formatter algorithm from the inspector #221

Closed waiting-for-dev closed 2 years ago

waiting-for-dev commented 2 years ago

Up to this point, the route inspector always returned a visually attractive representation of the routes. Now, that format has been extracted to a Hanami::Formatter::HumanFriendly class, while others are allowed to be injected.

That allows the creation of other algorithms that can be helpful for purposes beyond a visual inspection, like CSV, JSON, or import formats for API documentation and platforms.

As others can create their formatters, we're changing the visibility of Hanami::Inspector and Hanami::Route methods to be public.

We've taken the occasion to refactor the extracted code, so it doesn't mutate a variable. We've also removed the test on Hanami::Inspector#initialize as it stated something obvious, and the description was out of date since https://github.com/hanami/router/commit/9936225e36814fbed215d491479597c62b397b66 (no longer frozen).

There's a second commit fixing a Rubocop offense to make CI green.