This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U727QMZXMMA
Hey guys!
Are you aware of any tools which can automate Ruby files moving from the monolith to packages?
Something what could not just move files but also update the class namespace and all references.
bin/packs (installed through use_packs: https://github.com/rubyatscale/use_packs) has a command to move files from the monolith into packages (does some other nice things like moves the spec file too).
What’s special about this is that moving a file from the monolith to a pack doesn’t actually require a change to the file’s constant’s namespace (or its references). Moving a file from the monolith to a pack only changes the autoloaded portion of the filename (i.e. not the portion that affects constant namespacing/qualification).
I’d encourage thinking of moving files and updating constant names as separate problems, because it makes the most important bit (what belongs where) really easy whereas how something is referenced (also important, but a step later) is much harder to automate. That being said, I had looked into using spoom (a ruby client for the sorbet LSP) to automatically rename constant references across the codebase, but didn’t invest much time into it. As sorbet matures I think it’ll provide a nice avenue to do that sort of automatic refactor.
use_packs will actually do corrections for rubocop also. (Alex, keep me honest here… I seem to never be 100% accurate at telling apart the tooling we have open-sourced from Gusto and what is still internal-only)
Yes depending on what you mean. Rubocop doesn’t have the ability to automatically refactor constant namespace and references (to do this reliably you need type checking). use_packs will update rubocop ignores in .rubocop_todo.yml files so that you can move files without getting a barrage of rubocop failures.