Code Monkey home page Code Monkey logo

deep_merge's People

Contributors

andrewlipscomb avatar benlangfeld avatar danielsdeleo avatar fryguy avatar jaredbeck avatar jrafanie avatar jweiss avatar kindkid avatar koic avatar ktdreyer avatar mohammad-nabeel avatar msievers avatar rrottmann avatar sobakasu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deep_merge's Issues

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

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.

Inconsistent behaviour between bang and no-bang method

hash1 = { a: 1, b: 2 }
=> {:a=>1, :b=>2}

hash2 = { a: 3, c: 4 }
=> {:a=>3, :c=>4}

hash1.deep_merge(hash2)
=> {:a=>1, :b=>2, :c=>4}

hash1.deep_merge!(hash2)
=> {:a=>3, :b=>2, :c=>4}

This difference in behaviour seems counterintuitive. Usually the bang method is the destructive equivalent of the non-bang method returning the same result.

I want the behaviour of deep_merge! above where :a's value is overwritten but I don't want to apply it destructively to the original hash1 object. Can this be done?

new release?

Would it be possible to bump for a new release with the addition of the keep_array_duplicates? I know there hasn't really been anything else added since the merge back in August, but I'd love to use this feature.

Thanks!

Make Hash monkeypatching optional

Something like require 'deep_merge/core_ext' and without it you could use DeepMerge.merge(hash1, hash2) or hash1.extend(DeepMerge::Hash).merge(hash2)

push tags to github

When you tag releases, would you mind pushing the tags to GitHub? For example the latest version on Rubygems.org is 1.0.1, but the 1.0.1 tag is missing from the repository.

Receiver hash modified when using non-bang `#deep_merge`

Given that the Hash#merge method does not modify the receiver hash, I think it's really confusing that Hash#deep_merge does.

For#merge:

irb --simple-prompt merge.rb
>> h = {}
=> {}
>> h.merge(m: 1)
=> {:m=>1}
>> h
=> {}
>> h.merge!(m!: 2)
=> {:m!=>2}
>> h
=> {:m!=>2}

but for #deep_merge:

irb --simple-prompt deep_merge.rb
>> require 'deep_merge'
=> true
>> h = {}
=> {}
>> h.deep_merge(dm: 1)
=> {:dm=>1}
>> h
=> {:dm=>1}
>> h.deep_merge!(dm!: 2)
=> {:dm=>1, :dm!=>2}
>> h
=> {:dm=>1, :dm!=>2}

I see that #deep_merge! does have different behaviour for unmergeables, but I wonder if instead of using a ! suffix, is should instead use a prefix, in a similar manner to ko_deep_merge!, for consistency within this library.

Overall though, I think consistency with the stdlib is important, and therefore #deep_merge should not modify the receiver hash. As a test, I think this should not raise (as it currently does) {}.freeze.deep_merge(a: 1).

Inconsitent merge of true and false as string values and class

require 'deep_merge'
require 'yaml'

true_hash = { "string_val" => "true", "class_val" => true }
false_hash = { "string_val" => "false", "class_val" => false }

merged = false_hash.deep_merge(true_hash)

puts merged.to_yaml
$ ruby foo.rb 

---
string_val: 'false'
class_val: true

Strange merge behaviour with keep_array_duplicates option

Hi,

I'm facing a strange behavior with keep_array_duplicates option when destination hash is empty.
To illustrate I picked up the unit test case and changed hash_dst initial value to {}

hash_src = {"item" => ["2", "3"]}
hash_dst = {}
DeepMerge::deep_merge!(hash_src, hash_dst, {:keep_array_duplicates => true})
puts hash_dst

It produces:

{"item"=>["2", "3", "2", "3"]}

I was expecting something like :

{"item"=>["2", "3"]}

Am I wrong?

Using deep_merge with bundler and rails

When I use deep_merge with rails it messes up a couple of things like routing. In the documentation you mention that you should require 'deep_merge/rails_compat'.

When I do that using bundler however, my routing is still messed up. I assume bundler requires the gem automatically during bundler/setup, so the breaking code is still included.

Is there another way to use the gem with bundler? Thanks!

deep_merge overwriting works differently than Hash#merge

deep_merge behaves different than Hash#merge, where Hash#merge overwrites a key's value of the original hash if the hash being merged in contains the same key. The opposite is true for deep_merge.

$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin13.1.0]
$ irb
irb(main):001:0> require 'deep_merge'
=> true
irb(main):002:0> { key: 'left' }.merge({ key: 'right' })
=> {:key=>"right"}
irb(main):003:0> { key: 'left' }.deep_merge({ key: 'right' })
=> {:key=>"left"}

Is this as intended, or is this a bug in deep_merge?

Deep Merge non arrays

Is it possible to deep merge this
{:available=>{:inventory=>{:sordernum=>849836}}}
{:available=>{:inventory=>{:sordernum=>221836}}}

to produce
{:available=>{:inventory=>[{:sordernum=>849836},{:sordernum=>221836}]}}

Merging in empty strings

def test_deep_merge
  old = {:foo => "hello"}
  new = {:foo => ""}

  DeepMerge.deep_merge!(new, old)
  assert_equal "", old[:foo]
end

I would expect old[:foo] to be an empty string here. But it doesn't seem to be. Am I doing something wrong?

keep_array_duplicates is not documented

To my surprise duplicate array elements were not duplicated.
Only by looking into the source code I did see that there was an option for it.

I suggest to add it the the main documentation as well

already initialized constant DeepMerge::DEFAULT_FIELD_KNOCKOUT_PREFIX

Hi, here is what I am seeing every time my rails app starts:

/[...]/gems/deep_merge-1.0.1/lib/deep_merge/core.rb:5: warning: already initialized constant DeepMerge::DEFAULT_FIELD_KNOCKOUT_PREFIX
/[...]/gems/rails_config-0.4.2/lib/rails_config/vendor/deep_merge.rb:4: warning: previous definition of DEFAULT_FIELD_KNOCKOUT_PREFIX was here

My Gemfile:

gem 'deep_merge', require: 'deep_merge/rails_compat'

{:merge_nil_values => true} does not work

Source:
"DeletionPolicy": null (JSON Style, in ruby its nil ;-)
Destination:
"DeletionPolicy": "Snapshot"

Destination.deep_merge!(Source, {:merge_nil_values => true})

Debug:
==>merging: :DeletionPolicy => nil :: "Snapshot"

Make this a gem?

Any way we could make this a gem, or get these changes merged into the deep_merge gem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.