-
Notifications
You must be signed in to change notification settings - Fork 33
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
Make detail tuples typed-ish #837
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you show how this will simplify something in a controller?
It simplifies |
Co-authored-by: Carl Hörberg <[email protected]>
ok, i see it now. it's less code in |
It's not like |
Not yet, but it enables other refactoring to improve it. One purpose of this is to simplify the abstraction of different entities. I've struggled with
The "tree traversing" is a little bit of a mess because of macro language limitations, but the generated code should be straight forward. Moving the logic also makes it easier to test it. |
WHAT is this pull request doing?
"detail tuples" are
NamedTuple
s which causes a lot of limitations and struggle when refactoring.One approach to mitigate this would have been to declare a lot of structs for every case we need, but that would require a lot of work and make the code less flexible.
This PR will introduce
Metadata
which is a wrapper aroundNamedTuple
. This makes it possible to add helper methods on the details instead of doing a lot of "workarounds" where the data is accessed. Looking at the diff forsrc/lavinmq/http/controller.cr
one will see that the code is simplified.Values is wrapped in
Metadata::Value
which is forMetadata
whatJSON::Any
is toJSON
.One thing that maybe needs to be thought through and fixed is
Value#<=>
. It will probably almost always compare to values of the same type and thereby compare correct, but other edge cases maybe needs to be changed.HOW can this pull request be tested?
Run specs.