-
Notifications
You must be signed in to change notification settings - Fork 26
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
Create dump/1 for saving filters. #57
base: master
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.
I think this is a great start @gen1321. Here are my comments.
I think we need to more clearly represent the terminology here. While we have parse
for understanding data (which makes sense due to the human-like terms in there parameters), dump
doesn't quite give enough. I realized I originally used that word in my issue, but I think that encode_map_value
will work better since it gives the idea of what form we are encoding to. Additionally, when we implement the custom type, we don't want to overload the term dump
since that's used by Ecto.
Because I'm suggesting the addition of a Filtrex.Encoder.Map
(see individual comments), I think we should also be consistent and rename Filtrex.Encoder
to Filtrex.Encoder.Fragment
since it maps to Ecto fragment structures. If you need guidance on creating a protocol, checkout that encoder to get an idea.
As far as a custom type. I think that you would add Filtrex.Ecto.Type
as the module name. For implementation details, checkout my article on Medium on how to do this: https://medium.com/@rcdilorenzo/creating-a-custom-ecto-duration-type-994e32ad4613.
First of all thanks for a great review! It's a bit unclear to me how exactly you want to name/place encoders, my guess is:
|
Yes. That sounds good with one minor tweak on the names. Let's use |
About ecto type, how can we pass |
@gen1321 Ah, I hadn't thought about that. 🤔 I think we'll probably have to have a module that allows you to define your own type that uses a hardcoded configuration (or calls a module). For example, the helper module might be |
Is there something left? looks done to me |
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.
So sorry that I haven't circled back on this. Last semester of a graduate degree will do that to a person... 😄 These are the final changes I think are necessary. I'll try to be quicker to respond as you make changes. Thanks for sticking it out!
%{ | ||
"type" => type, | ||
"conditions" => Enum.map(conditions, &Filtrex.Condition.encode_condition/1), | ||
"sub_filters" => Enum.map(sub_filters, &encode_sub_filters/1) |
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.
Because filtrex
elsewhere allows for an arbitrary level of recursion for sub_filters
, let's make sure this is consistent with this encoding feature being added. Checkout schema.json for the definition.
@rcdilorenzo done |
] | ||
}, | ||
], | ||
"sub_filters" => [] |
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.
Have you actually seen the recursion working properly? It looks like the code is right, but it might be worth it to throw in an example where we have a sub-filter that has to be dumped. (I'll do a final review to make sure we didn't miss anything, but everything in the new commits look good.)
Closes #42. The issue also mentions implementing Ecto Type. If you can provide an example, I will do my best to implement this too.