Update how generics work for Avram::Attribute#586
Merged
matthewmcgarvey merged 1 commit intoluckyframework:masterfrom Jan 4, 2021
Merged
Update how generics work for Avram::Attribute#586matthewmcgarvey merged 1 commit intoluckyframework:masterfrom
matthewmcgarvey merged 1 commit intoluckyframework:masterfrom
Conversation
matthewmcgarvey
commented
Jan 4, 2021
| getter :param_key | ||
| getter name : Symbol | ||
| setter value : T? | ||
| getter param_key : String |
Member
Author
There was a problem hiding this comment.
I change symbol to type declaration out of preference, hopefully that's ok 😄
| @errors << message | ||
| end | ||
|
|
||
| private def perform_add_error(message : (Proc | Avram::CallableErrorMessage)) |
Member
Author
There was a problem hiding this comment.
Moving this overload into the add_error method simplifies the code and error stack traces
eb43e92 to
7707544
Compare
jwoertink
approved these changes
Jan 4, 2021
Member
jwoertink
left a comment
There was a problem hiding this comment.
I think this makes sense. We lock in the type the attribute wants, but say the value could be nil. 👍
| if value.is_a?(Avram::Uploadable | String) && value.blank? | ||
| nil | ||
| else | ||
| value |
Member
There was a problem hiding this comment.
I wonder if we should be adding a not_nil! here so the compiler knows this type is locked in? 🤔
Member
Author
There was a problem hiding this comment.
The value can always be nil, this code is just the logic that also treats blank strings as nil.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I'm starting to look into #408 but noticed that the generics for
Avram::Attributewere a bit weird. We document that values for attributes are always nilable but that wasn't necessarily true. It's always nilable because where ever we were "new-ing" up an attribute we were doing so in a macro and adding in a?to whatever type was supplied but the attribute's type could have been anything (including not nilable). We can avoid doing that in the macros by making the attribute's value nilable within the class. SoAvram::Attribute(String?)becomesAvram::Attribute(String)butAvram::Attribute(String)#valueis stillString?This would be a breaking change for anyone referencing the type. For instance, some validations had to be updated so anyone that defined their own and specified the type will be broken.