hash_diff 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +15 -11
- data/lib/hash_diff.rb +2 -0
- data/lib/hash_diff/comparison.rb +9 -2
- data/lib/hash_diff/version.rb +1 -1
- data/spec/hash_diff/comparison_spec.rb +36 -9
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0c353c43e17ed7d833fe9edf3fd4e6ec4af96aa6
         | 
| 4 | 
            +
              data.tar.gz: b8b050b80bb2c69ad5e4b79a96c30cc1ede24092
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d528f1366911a7b69bff0af027621b0e37ca22b97b4150b4853277548f2ee242701a4320701a9432c6acfe5333b0f2b4df35ca3b0d9e401d16dab9086774086d
         | 
| 7 | 
            +
              data.tar.gz: c95598db8dadac025c0f6526d55ca43ab4bf2154f782d6d1402ef3da88c7df5be5f3597f014c984e4d6858fd2cb84a364f37d9ee3c37124c73411ebb79e2be3f
         | 
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            # HashDiff
         | 
| 2 | 
            +
             | 
| 2 3 | 
             
            [](https://travis-ci.org/CodingZeal/hash_diff) [](https://codeclimate.com/github/CodingZeal/hash_diff) [](http://badge.fury.io/rb/hash_diff)
         | 
| 3 4 |  | 
| 4 5 | 
             
            Deep comparison of Ruby Hash objects
         | 
| @@ -31,7 +32,8 @@ Easily find the differences between two Ruby hashes. | |
| 31 32 | 
             
                    one: 'foo1'
         | 
| 32 33 | 
             
                  }
         | 
| 33 34 | 
             
                },
         | 
| 34 | 
            -
                num: 1
         | 
| 35 | 
            +
                num: 1,
         | 
| 36 | 
            +
                favorite_restaurant: "Shoney's"
         | 
| 35 37 | 
             
              }
         | 
| 36 38 |  | 
| 37 39 | 
             
              right = {
         | 
| @@ -43,7 +45,8 @@ Easily find the differences between two Ruby hashes. | |
| 43 45 | 
             
                    two: 'foo2'
         | 
| 44 46 | 
             
                  }
         | 
| 45 47 | 
             
                },
         | 
| 46 | 
            -
                word: 'monkey'
         | 
| 48 | 
            +
                word: 'monkey',
         | 
| 49 | 
            +
                favorite_restaurant: nil
         | 
| 47 50 | 
             
              }
         | 
| 48 51 |  | 
| 49 52 | 
             
              hash_diff = HashDiff::Comparison.new( left, right )
         | 
| @@ -52,19 +55,23 @@ Easily find the differences between two Ruby hashes. | |
| 52 55 | 
             
            Comparison#diff returns the left and right side differences
         | 
| 53 56 |  | 
| 54 57 | 
             
            ```ruby
         | 
| 55 | 
            -
              hash_diff.diff # => { foo: ["bar", "bar2"], bar: ["foo", "foo2"], nested: { foo: ["bar", "bar2"], bar: { one: ["foo1",  | 
| 58 | 
            +
              hash_diff.diff # => { foo: ["bar", "bar2"], bar: ["foo", "foo2"], nested: { foo: ["bar", "bar2"], bar: { one: ["foo1", HashDiff::NO_VALUE], two: [HashDiff::NO_VALUE, "foo2"] } }, num:  [1, HashDiff::NO_VALUE], word: [HashDiff::NO_VALUE, "monkey"], favorite_restaurant: ["Shoney's", nil] }
         | 
| 56 59 | 
             
            ```
         | 
| 57 60 |  | 
| 61 | 
            +
            #### Missing keys
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            When there is a key that exists on one side it will return `HashDiff::NO_VALUE` to represent a missing key.
         | 
| 64 | 
            +
             | 
| 58 65 | 
             
            Comparison#left_diff returns only the left side differences
         | 
| 59 66 |  | 
| 60 67 | 
             
            ```ruby
         | 
| 61 | 
            -
              hash_diff.left_diff # => { | 
| 68 | 
            +
              hash_diff.left_diff # => {:foo=>"bar2", :bar=>"foo2", :nested=>{:foo=>"bar2", :bar=>{:one=>HashDiff::NO_VALUE, :two=>"foo2"}}, :num=>HashDiff::NO_VALUE, :favorite_restaurant=>nil, :word=>"monkey"}
         | 
| 62 69 | 
             
            ```
         | 
| 63 70 |  | 
| 64 71 | 
             
            Comparison#right_diff returns only the right side differences
         | 
| 65 72 |  | 
| 66 73 | 
             
            ```ruby
         | 
| 67 | 
            -
              hash_diff.right_diff # => { | 
| 74 | 
            +
              hash_diff.right_diff # => {:foo=>"bar", :bar=>"foo", :nested=>{:foo=>"bar", :bar=>{:one=>"foo1", :two=>HashDiff::NO_VALUE}}, :num=>1, :favorite_restaurant=>"Shoney's", :word=>HashDiff::NO_VALUE}
         | 
| 68 75 | 
             
            ```
         | 
| 69 76 |  | 
| 70 77 | 
             
            You can also use these shorthand methods
         | 
| @@ -87,14 +94,11 @@ Hash#diff is not provided by default, and monkey patching is frowned upon by som | |
| 87 94 | 
             
              left.diff(right) # => { foo: 'baz' }
         | 
| 88 95 | 
             
            ```
         | 
| 89 96 |  | 
| 90 | 
            -
            ##  | 
| 91 | 
            -
             | 
| 92 | 
            -
            Authored by Adam Cuppy (@acuppy) of Coding ZEAL (http://codingzeal.com)
         | 
| 97 | 
            +
            ## License
         | 
| 93 98 |  | 
| 94 | 
            -
             | 
| 99 | 
            +
            Authored by the Engineering Team of [Coding ZEAL](https://codingzeal.com?utm_source=github)
         | 
| 95 100 |  | 
| 96 | 
            -
             | 
| 97 | 
            -
            enjoy :)
         | 
| 101 | 
            +
            Copyright (c) 2017 Zeal, LLC. Licensed under the [MIT license](https://opensource.org/licenses/MIT).
         | 
| 98 102 |  | 
| 99 103 | 
             
            ## Contributing
         | 
| 100 104 |  | 
    
        data/lib/hash_diff.rb
    CHANGED
    
    
    
        data/lib/hash_diff/comparison.rb
    CHANGED
    
    | @@ -38,7 +38,7 @@ module HashDiff | |
| 38 38 | 
             
                end
         | 
| 39 39 |  | 
| 40 40 | 
             
                def equal?(key)
         | 
| 41 | 
            -
                  left | 
| 41 | 
            +
                  value_with_default(left, key) == value_with_default(right, key)
         | 
| 42 42 | 
             
                end
         | 
| 43 43 |  | 
| 44 44 | 
             
                def hash?(value)
         | 
| @@ -53,8 +53,15 @@ module HashDiff | |
| 53 53 | 
             
                  if comparable?(key)
         | 
| 54 54 | 
             
                    self.class.new(left[key], right[key]).find_differences(&reporter)
         | 
| 55 55 | 
             
                  else
         | 
| 56 | 
            -
                    reporter.call( | 
| 56 | 
            +
                    reporter.call(
         | 
| 57 | 
            +
                      value_with_default(left, key),
         | 
| 58 | 
            +
                      value_with_default(right, key)
         | 
| 59 | 
            +
                    )
         | 
| 57 60 | 
             
                  end
         | 
| 58 61 | 
             
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def value_with_default(obj, key)
         | 
| 64 | 
            +
                  obj.fetch(key, NO_VALUE)
         | 
| 65 | 
            +
                end
         | 
| 59 66 | 
             
              end
         | 
| 60 67 | 
             
            end
         | 
    
        data/lib/hash_diff/version.rb
    CHANGED
    
    
| @@ -2,10 +2,37 @@ require "spec_helper" | |
| 2 2 |  | 
| 3 3 | 
             
            describe HashDiff::Comparison do
         | 
| 4 4 |  | 
| 5 | 
            -
              let(:app_v1_properties) { | 
| 6 | 
            -
             | 
| 5 | 
            +
              let(:app_v1_properties) {
         | 
| 6 | 
            +
                {
         | 
| 7 | 
            +
                  foo: 'bar',
         | 
| 8 | 
            +
                  bar: 'foo',
         | 
| 9 | 
            +
                  nested: {
         | 
| 10 | 
            +
                    foo: 'bar',
         | 
| 11 | 
            +
                    bar: {
         | 
| 12 | 
            +
                      one: 'foo1'
         | 
| 13 | 
            +
                    }
         | 
| 14 | 
            +
                  },
         | 
| 15 | 
            +
                  num: 1,
         | 
| 16 | 
            +
                  word: nil
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
              }
         | 
| 19 | 
            +
              let(:app_v2_properties) {
         | 
| 20 | 
            +
                {
         | 
| 21 | 
            +
                  foo: 'bar2',
         | 
| 22 | 
            +
                  bar: 'foo2',
         | 
| 23 | 
            +
                  nested: {
         | 
| 24 | 
            +
                    foo: 'bar2',
         | 
| 25 | 
            +
                    bar: {
         | 
| 26 | 
            +
                      two: 'foo2'
         | 
| 27 | 
            +
                    }
         | 
| 28 | 
            +
                  },
         | 
| 29 | 
            +
                  word: 'monkey'
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
              }
         | 
| 7 32 |  | 
| 8 | 
            -
              subject(:comparison) { | 
| 33 | 
            +
              subject(:comparison) {
         | 
| 34 | 
            +
                HashDiff::Comparison.new(app_v1_properties, app_v2_properties)
         | 
| 35 | 
            +
              }
         | 
| 9 36 |  | 
| 10 37 | 
             
              describe "#diff" do
         | 
| 11 38 | 
             
                subject { comparison.diff }
         | 
| @@ -18,11 +45,11 @@ describe HashDiff::Comparison do | |
| 18 45 | 
             
                      nested: {
         | 
| 19 46 | 
             
                        foo: ["bar", "bar2"],
         | 
| 20 47 | 
             
                        bar: {
         | 
| 21 | 
            -
                          one: ["foo1",  | 
| 22 | 
            -
                          two: [ | 
| 48 | 
            +
                          one: ["foo1", HashDiff::NO_VALUE],
         | 
| 49 | 
            +
                          two: [HashDiff::NO_VALUE, "foo2"]
         | 
| 23 50 | 
             
                        }
         | 
| 24 51 | 
             
                      },
         | 
| 25 | 
            -
                      num:  [1,  | 
| 52 | 
            +
                      num:  [1, HashDiff::NO_VALUE],
         | 
| 26 53 | 
             
                      word: [nil, "monkey"]
         | 
| 27 54 | 
             
                    }
         | 
| 28 55 | 
             
                  }
         | 
| @@ -57,11 +84,11 @@ describe HashDiff::Comparison do | |
| 57 84 | 
             
                    nested: {
         | 
| 58 85 | 
             
                      foo: "bar2",
         | 
| 59 86 | 
             
                      bar: {
         | 
| 60 | 
            -
                        one:  | 
| 87 | 
            +
                        one: HashDiff::NO_VALUE,
         | 
| 61 88 | 
             
                        two: "foo2"
         | 
| 62 89 | 
             
                      }
         | 
| 63 90 | 
             
                    },
         | 
| 64 | 
            -
                    num:   | 
| 91 | 
            +
                    num:  HashDiff::NO_VALUE,
         | 
| 65 92 | 
             
                    word: "monkey"
         | 
| 66 93 | 
             
                  }
         | 
| 67 94 | 
             
                }
         | 
| @@ -80,7 +107,7 @@ describe HashDiff::Comparison do | |
| 80 107 | 
             
                      foo: "bar",
         | 
| 81 108 | 
             
                      bar: {
         | 
| 82 109 | 
             
                        one: "foo1",
         | 
| 83 | 
            -
                        two:  | 
| 110 | 
            +
                        two: HashDiff::NO_VALUE
         | 
| 84 111 | 
             
                      }
         | 
| 85 112 | 
             
                    },
         | 
| 86 113 | 
             
                    num:  1,
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: hash_diff
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Coding Zeal
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2018-01-10 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         | 
| @@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 93 93 | 
             
                  version: '0'
         | 
| 94 94 | 
             
            requirements: []
         | 
| 95 95 | 
             
            rubyforge_project: 
         | 
| 96 | 
            -
            rubygems_version: 2. | 
| 96 | 
            +
            rubygems_version: 2.5.2
         | 
| 97 97 | 
             
            signing_key: 
         | 
| 98 98 | 
             
            specification_version: 4
         | 
| 99 99 | 
             
            summary: Deep Ruby Hash comparison
         |