Don't assume nilable when #__tapioca_type
is provided
#2126
+58
−19
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
#__tapioca_type
is meant to serve as an escape hatch to define arbitrary types for ActiveModel attributes. Currently, this escape hatch is limited, because it still assumes that all attributes are nilable.The
#__tapioca_type
method should have full control over what type is emitted to the RBI file.Implementation
This PR adds
.assume_nilable?
toActiveModelTypeHelper
. This method will only return false if the ActiveModel type implements#__tapioca_type
.It is the responsibility of the person who defined
#__tapioca_type
to wrap the type inT.nilable
.Alternatives:
ActiveModel::Type::Value
to implement#__tapioca_nilable?
..as_nilable_type
inActiveModelTypeHelper.type_for
to avoid adding another public method. This is probably the simpler solution, but it would updates to the expected return values in tests.Tests
This PR includes tests.