hash_diff 0.5.1 → 0.6.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 +8 -8
- data/Gemfile +1 -3
- data/README.md +23 -0
- data/hash_diff.gemspec +1 -1
- data/lib/hash_diff.rb +17 -1
- data/lib/hash_diff/version.rb +1 -1
- data/spec/hash_diff_spec.rb +39 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NmI4YmU1N2U2YWY3MjI1YTA5M2NiMDExZjViNDk3YjE5ZTE1YTVmYg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
ZmIxMzIyODkzMzBjOTg5ODRkMmQ0MTRhMTNhMzAwMDAzMGM1MmIxMg==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
M2UxM2M2NmYzOTVhYTAwNzg2NWJlY2RmMDQyNjc0YzgzNDA1NDA1M2YyZGYz
|
|
10
|
+
ZmMzNTAzY2UxMGU0MDI3MWFiYWI4NTBjNDQ4OTAxNjgxYTZlZGUzMjE4YmM3
|
|
11
|
+
ZjA0OTc3ZGVjZjk2ZTJlZDBkYzU1ZDYzNDY4OThlZmZhN2MxYTU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NjI4OTQ3MzViNjZiYzE0MjNlYzQwNjM4YTBmNjM0NTRjMDI4YWU5YzU0MTky
|
|
14
|
+
MjBiMzA5M2NmOTRhYjU5ZDg2ZGE5ZGEyNWQyOWQ1MWM2NTdlYjJhYWMyZDBk
|
|
15
|
+
MTVlZWQ3YzJjNDAyZmE2MmRiZDBjOWQxMDVmMWNmYmJlNTZmODk=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -66,6 +66,29 @@ Comparison#right_diff returns only the right side differences
|
|
|
66
66
|
hash_diff.right_diff # => { foo: "bar", bar: "foo", nested: { foo: "bar", bar: { one: "foo1", two: nil } }, num: 1, word: nil }
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
You can also use these shorthand methods
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
HashDiff.diff(left, right)
|
|
73
|
+
HashDiff.left_diff(left, right)
|
|
74
|
+
HashDiff.right_diff(left, right)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Hash#diff is not provided by default, and monkey patching is frowned upon by some, but to provide a one way shorthand, use the following code snippet.
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
class Hash
|
|
81
|
+
def diff(right)
|
|
82
|
+
HashDiff.right_diff(self, right)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
left = { foo: 'bar', num: 1 }
|
|
87
|
+
right = { foo: 'baz', num: 1 }
|
|
88
|
+
|
|
89
|
+
left.diff(right) # => { foo: 'baz' }
|
|
90
|
+
```
|
|
91
|
+
|
|
69
92
|
## Contributing
|
|
70
93
|
|
|
71
94
|
1. Fork it
|
data/hash_diff.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Coding Zeal", "Adam Cuppy"]
|
|
10
10
|
spec.email = ["info@codingzeal.com"]
|
|
11
11
|
spec.description = %q{Diff tool for deep Ruby hash comparison}
|
|
12
|
-
spec.summary = %q{Deep Hash comparison}
|
|
12
|
+
spec.summary = %q{Deep Ruby Hash comparison}
|
|
13
13
|
spec.homepage = "https://github.com/CodingZeal/hash_diff"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
data/lib/hash_diff.rb
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
require "hash_diff/version"
|
|
2
|
-
require "hash_diff/comparison"
|
|
2
|
+
require "hash_diff/comparison"
|
|
3
|
+
|
|
4
|
+
module HashDiff
|
|
5
|
+
class << self
|
|
6
|
+
def diff(*args)
|
|
7
|
+
Comparison.new(*args).diff
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def left_diff(*args)
|
|
11
|
+
Comparison.new(*args).left_diff
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def right_diff(*args)
|
|
15
|
+
Comparison.new(*args).right_diff
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/hash_diff/version.rb
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe HashDiff do
|
|
4
|
+
describe ".diff" do
|
|
5
|
+
let(:comparison) { double("comparison") }
|
|
6
|
+
let(:left) { double("left") }
|
|
7
|
+
let(:right) { double("right") }
|
|
8
|
+
|
|
9
|
+
it "delegates to Comparison#diff" do
|
|
10
|
+
HashDiff::Comparison.should_receive(:new).with(left, right).and_return(comparison)
|
|
11
|
+
comparison.should_receive(:diff)
|
|
12
|
+
HashDiff.diff(left, right)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe ".left_diff" do
|
|
17
|
+
let(:comparison) { double("comparison") }
|
|
18
|
+
let(:left) { double("left") }
|
|
19
|
+
let(:right) { double("right") }
|
|
20
|
+
|
|
21
|
+
it "delegates to Comparison#left_diff" do
|
|
22
|
+
HashDiff::Comparison.should_receive(:new).with(left, right).and_return(comparison)
|
|
23
|
+
comparison.should_receive(:left_diff)
|
|
24
|
+
HashDiff.left_diff(left, right)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe ".right_diff" do
|
|
29
|
+
let(:comparison) { double("comparison") }
|
|
30
|
+
let(:left) { double("left") }
|
|
31
|
+
let(:right) { double("right") }
|
|
32
|
+
|
|
33
|
+
it "delegates to Comparison#right_diff" do
|
|
34
|
+
HashDiff::Comparison.should_receive(:new).with(left, right).and_return(comparison)
|
|
35
|
+
comparison.should_receive(:right_diff)
|
|
36
|
+
HashDiff.right_diff(left, right)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
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: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Coding Zeal
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- lib/hash_diff/comparison.rb
|
|
71
71
|
- lib/hash_diff/version.rb
|
|
72
72
|
- spec/hash_diff/comparison_spec.rb
|
|
73
|
+
- spec/hash_diff_spec.rb
|
|
73
74
|
- spec/spec_helper.rb
|
|
74
75
|
homepage: https://github.com/CodingZeal/hash_diff
|
|
75
76
|
licenses:
|
|
@@ -94,7 +95,8 @@ rubyforge_project:
|
|
|
94
95
|
rubygems_version: 2.1.11
|
|
95
96
|
signing_key:
|
|
96
97
|
specification_version: 4
|
|
97
|
-
summary: Deep Hash comparison
|
|
98
|
+
summary: Deep Ruby Hash comparison
|
|
98
99
|
test_files:
|
|
99
100
|
- spec/hash_diff/comparison_spec.rb
|
|
101
|
+
- spec/hash_diff_spec.rb
|
|
100
102
|
- spec/spec_helper.rb
|