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
Hashie::Extensions::DeepGrep #528
base: master
Are you sure you want to change the base?
Conversation
I like it. Would vote to merge if you can finish it with docs & al. |
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.
A few suggestions
Thanks Bobby :) Co-authored-by: Bobby McDonald <BobbyMcWho@users.noreply.github.com>
Because there is already an |
LGTM, leaving final call(s) to @michaelherold, needs a README update, please |
Hi @vmarutha, thank you for your contribution! I've started to dive into this and I have a few things that I've found.
books = {
"Uncategorized" => [
{ title: "Ruby for beginners", pages: 120 },
{ title: "CSS for intermediates", pages: 80 },
],
"Collection of Elixir books" => [
{ title: "Programming Elixir 1.9", pages: 689 }
],
"Collection of Ruby books" => [
{ title: "That other programming language by Matz", pages: 578 }
]
} Given the way you wrote up the intent of the method, I would expect a [
{ title: "Ruby for beginners", pages: 120 },
{
"Collection of Ruby books" => [
{ title: "That other programming language by Matz", pages: 578 }
]
}
] I expect the first Hash in the result because "Ruby" is in the title of the book. I expect the second Hash because the key "Collection of Ruby Books" has the string "Ruby" in it, which would select that whole subtree of the parent Hash. Instead, this example returns
Does my understanding of the intent of the method mesh with your intention in (2)? Or am I off-base in my understanding? If it would be helpful, I can attach a commit with some specs. |
Hi @michaelherold, Thanks for the feedback :) So I tried that exact example, and I got two items as the results, one of which was I agree that returning I noticed this about the implementation, and I guess it is a question on whether we would like to have the container object returned. It may be inelegant if the match is near the parent node of the hash (ex But I think it would be effective for deeper nested hashes. ex What do you think about this? Following your suggestion about not using mixins, I'm thinking of having Also maybe it is best to expose another method that is a more stricter grep, one without returning the complete container object to try to address your main concern. I'd have to play around with this first. As always, open to suggestions and feedback here. |
Hi @vmarutha, Sorry, it looks like you might have been waiting for feedback, which was my mistake. I'll answer your questions from your last message.
Hmm, I must have botched something in my setup then!
Yes, I think that's likely. I wonder if we can have an exit handler that prevents returning the original argument?
I think you're right. Ideally, we would prevent returning the outermost object but return any contained hash that matches. What do you think about that?
Yes, that's exactly what I had in mind. 😄
That could be a good alternative to my suggestion above! I'd love to see how it feels. |
Grep for hash.
Currently, if a key/value matches the pattern, the result will include the parent hash. This is because we are preserving the match context, and I think it would be useful to retain.
If a value matches the pattern and is in a list, the associated key is not returned. Thinking on how to make this a more uniform results list irregardless of matching data type. This may be a bit tricky though especially with enumerables as the key or value in the hash. Let me know if you have suggestions for this case!
Open to merge as is, and comeback to above edge case later on since the main functionality still works.
Edit: Thanks for all suggestions, finally opened this one up :p