Avoid raising when constantizing from paths #1414
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
#968 added support for generating DSL RBI via a path like
bin/tapioca dsl app/models
. The way it works is usingStatic::SymbolLoader.symbols_from_paths
to find all constants defined in those paths and then acting as if you calledbin/tapioca dsl <those constants>
.When testing this out for the first time, I realized that sometimes
symbols_from_paths
found constants that weren't actually loaded (or loadable) and would then raise an exception. Two common examples in our codebase:In this example,
Foo::BAR
is a constant returned fromsymbols_from_paths
but you can't actually reference it outside the eigenclass.bin/tapioca dsl packs/xyz
which is a folder than contains bothapp
andspec
so it found a few constants from tests and blew up trying to load them.Implementation
When generating DSL for specific constants like
bin/tapioca dsl Some::Constant
we raise if that constant can't be resolved. This makes sense since you're explicitly asking us to generate DSL for a specific constant.We previously had the same behavior for constants derived from given paths, however this PR changes that behavior so we'll simply ignore constants that cannot be resolved. This makes sense to me since by doing
bin/tapioca dsl some/path
you're essentially saying "generate RBI for whatever you can insome/path
".Tests
Added a test for the eigenclass case and confirmed it failed before and passed after this change. I also tested out this branch of tapioca on Gusto's codebase and it worked as expected 馃憤