Skip to content
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

Feature suggestion: Allow a block to passed, following same standard used in Ruby & Rails #39

Open
salgadobreno opened this issue Jul 4, 2019 · 1 comment

Comments

@salgadobreno
Copy link

Hi, thanks for the cool gem 8)

So, there's a feature suggestion, it would be nice to allow passing a block to be yielded when there's a conflict not in Hash or Array lets say, as Rails deep_merge and Hash merge do. It could serve for things like doing calculations and such or allowing the decision to override a value to be done in other ways, in my use case, I wanted to sum one of the values.

I'll probably try coming up with a monkey patch for my purposes, I'll say already I'm very lazy but I could try coming up with a pull request, specially if the feature is desirable.

@science
Copy link

science commented Sep 2, 2019

Hey @salgadobreno - seems like a great idea (I'm the original author, but not the current maintainer). I believe I wrote this before that practice was standardized, so it would be great to bring this lib inline.

I think you'd approach this by providing block handling on this line:
https://github.com/danielsdeleo/deep_merge/blob/master/lib/deep_merge/core.rb#L78

And then on these wrapping methods: https://github.com/danielsdeleo/deep_merge/blob/master/lib/deep_merge/deep_merge_hash.rb

Then you'd need to track state of the merge with some new variable starting at that L78 above. Shouldn't be too tough, but deciding what is a conflict and what isn't will be a bit of a judgment call maybe, but I'd definitely encourage you to give it a try, and send a pull request here.. I think I have perms to approve PRs on Daniel's repo, so you can tag me or him to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants