-
Notifications
You must be signed in to change notification settings - Fork 64
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
Look in to moving away from monkey-patched core types #1068
Comments
Just want to note that the level of monkey-patching is very low. As far as I see, it's just adding the I can't say anything about the internal motivations for changing this. |
Yea came here to say looks like this will be resolved via crystal-lang/crystal#15065. So at this point sounds like the only downside is custom type support being more involved. |
Thanks for chiming in and letting me know. That does make me feel better about holding off on this. I'd much rather save this level of change for a 2.0 than have to do things sooner, so that's good news. 🙌 |
I'm in general very weary of monkeypatching, but I think here it presents a meaningful and helpful interface. I would back switching the patch to call the method |
We patch all of the basic types that Avram supports like this:
avram/src/avram/charms/bool_extensions.cr
Lines 1 to 6 in 6922463
This is used in a lot of different places like
avram/src/avram/criteria.cr
Line 121 in 6922463
avram/src/avram/add_column_attributes.cr
Line 66 in 6922463
avram/src/avram/base_query_template.cr
Line 13 in 6922463
The idea is that your column specifies a type like
admin : Bool
, then we callBool.adapter.whatever
internally. I believe the original intention was to have a swappable adapter to handle doing different things, but we never got around to that.The other bit is this ensures that Bool related methods are handled by Bool and String related methods are handled by String which gives Lucky (and Avram) an extra layer of type-safety without having to fight the compiler.
There are some downsides to this, and the most recent is that the new
crystal tool unreachable
doesn't work with Lucky at all, and it may boil down to this.Another issue is that it makes creating custom types a lot more involved.
I think we can come up with a better interface for this which will also alleviate monkey-patching the stdlib types
The text was updated successfully, but these errors were encountered: