-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for parameter defaults #8
Comments
|
Thanks for chiming in, I really like the idea of making it a transform like key casing/alias. But we'd probably only want to apply the default if the param is missing, so that we don't clobber values, because an empty string and nil could be expected values for some. Not sure if a transform can achieve that, but worth looking into — may have to be its own |
That would be cleaner for running it before coerce, IIRC, which means that the final type info only lives in one place. Whether actual transforms (like, from the transforms keyword, not other stuff in the array) should happen before or after... I could go either way, but do think that since the example in the README shows something being restructured (so that is an intended purpose), my gut is that it makes sense to be before, since otherwise you'd end up writing anything similar to that restructuring code twice. I agree on empty? though, that's one of the main reasons I thought it was a suboptimal approach. |
Yep, the problem with using transforms is that iirc the transforms only apply to parameters that are provided — i.e. you won't be able to provide a default for a missing parameter. That's why I was thinking a separate step in the pipeline, barring big changes. But maybe I'm wrong… I'll need to spend time reorienting myself with the internals to see if it's possible via the transformer: typed_params/lib/typed_params/transformer.rb Lines 5 to 10 in 8652694
I think we may be able to check if Open to a PR if you're up for it, ofc. |
Might be useful for things like roles, pagination, etc.
The text was updated successfully, but these errors were encountered: