tapioca
tapioca copied to clipboard
Support generating DSL RBI by path
Motivation
We often want to generate RBI for every model, worker, etc inside a namespace. Currently the only way to do that involves crawling ObjectSpace in a console or doing grep/sed magic to get the set of constants. We wanted an easier way to do this.
Another future-facing use-case is being able to run tapioca dsl --verify some/specific/path
.
- Sidenote: At the moment,
--verify
fails unless it's called with no arguments since it thinks there's stale RBI, but that's something that can be fixed separately.
Implementation
I thought it would be most ergonomic to be able to pass directory/filenames as args to the tapioca dsl
but currently it's assumed that any non-flag args passed will be class names. Luckily, ruby class names and file names follow disjoint patterns:
- class names must start with a capital letter or colon
- path names typically (99.9% of path names I've ever seen) start with a lower case letter or slash.
Given that, we use that heuristic to split the passed args into either class names or paths and then treat them appropriately downstream. For paths, we use SorbetHelpers.sorbet
to call tc --print=symbol-table-json
and then parse the defined class names from that output.
Tests
See tests