hash_diff 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -26
- data/lib/hash_diff.rb +9 -1
- data/lib/hash_diff/version.rb +1 -1
- data/spec/hash_diff_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 138f8fc905ed5caa8160dc05131bfd1d1f484908
|
4
|
+
data.tar.gz: 7bc15e4a8d6e0fa94bd1c4bc0f29d67e34ad7dc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 702c7c4b34e50a6b410ed191a57e185a55ba96d3ca95c855b68f349fc267f1204ab00bd439fa248d23ab22a456aff5a84c0fac04356004017a7d6ce77076e50d
|
7
|
+
data.tar.gz: 14211e477a53d725526d6f7c271338a49727d81bafa447842cef00ded7e561184f590478294a1b7a19f868c122e2c60f8e4dd1969e7cc470f78cd6d96477f282
|
data/README.md
CHANGED
@@ -22,28 +22,28 @@ Or install it yourself as:
|
|
22
22
|
Easily find the differences between two Ruby hashes.
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
left = {
|
26
|
-
foo: 'bar',
|
27
|
-
bar: 'foo',
|
28
|
-
nested: {
|
29
|
-
foo: 'bar',
|
30
|
-
bar: {
|
31
|
-
one: 'foo1'
|
32
|
-
}
|
33
|
-
},
|
34
|
-
num: 1
|
25
|
+
left = {
|
26
|
+
foo: 'bar',
|
27
|
+
bar: 'foo',
|
28
|
+
nested: {
|
29
|
+
foo: 'bar',
|
30
|
+
bar: {
|
31
|
+
one: 'foo1'
|
32
|
+
}
|
33
|
+
},
|
34
|
+
num: 1
|
35
35
|
}
|
36
36
|
|
37
|
-
right = {
|
38
|
-
foo: 'bar2',
|
39
|
-
bar: 'foo2',
|
40
|
-
nested: {
|
41
|
-
foo: 'bar2',
|
42
|
-
bar: {
|
43
|
-
two: 'foo2'
|
44
|
-
}
|
45
|
-
},
|
46
|
-
word: 'monkey'
|
37
|
+
right = {
|
38
|
+
foo: 'bar2',
|
39
|
+
bar: 'foo2',
|
40
|
+
nested: {
|
41
|
+
foo: 'bar2',
|
42
|
+
bar: {
|
43
|
+
two: 'foo2'
|
44
|
+
}
|
45
|
+
},
|
46
|
+
word: 'monkey'
|
47
47
|
}
|
48
48
|
|
49
49
|
hash_diff = HashDiff::Comparison.new( left, right )
|
@@ -75,14 +75,11 @@ You can also use these shorthand methods
|
|
75
75
|
HashDiff.right_diff(left, right)
|
76
76
|
```
|
77
77
|
|
78
|
-
Hash#diff is not provided by default, and monkey patching is frowned upon by some, but to provide a one way shorthand
|
78
|
+
Hash#diff is not provided by default, and monkey patching is frowned upon by some, but to provide a one way shorthand call `HashDiff.patch!`
|
79
79
|
|
80
80
|
```ruby
|
81
|
-
|
82
|
-
|
83
|
-
HashDiff.left_diff(self, right)
|
84
|
-
end
|
85
|
-
end
|
81
|
+
# run prior to implementation
|
82
|
+
HashDiff.patch!
|
86
83
|
|
87
84
|
left = { foo: 'bar', num: 1 }
|
88
85
|
right = { foo: 'baz', num: 1 }
|
data/lib/hash_diff.rb
CHANGED
@@ -14,5 +14,13 @@ module HashDiff
|
|
14
14
|
def right_diff(*args)
|
15
15
|
Comparison.new(*args).right_diff
|
16
16
|
end
|
17
|
+
|
18
|
+
def patch!
|
19
|
+
Hash.class_eval do
|
20
|
+
def diff right
|
21
|
+
HashDiff.left_diff self, right
|
22
|
+
end
|
23
|
+
end unless self.class.respond_to? :diff
|
24
|
+
end
|
17
25
|
end
|
18
|
-
end
|
26
|
+
end
|
data/lib/hash_diff/version.rb
CHANGED
data/spec/hash_diff_spec.rb
CHANGED
@@ -39,4 +39,16 @@ describe HashDiff do
|
|
39
39
|
|
40
40
|
it { expect(subject).to eq({ foo: 'bar' }) }
|
41
41
|
end
|
42
|
+
|
43
|
+
describe ".patch!" do
|
44
|
+
before { described_class.patch! }
|
45
|
+
|
46
|
+
it "patches #diff to Hash" do
|
47
|
+
expect({}).to respond_to(:diff)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "leaves Object alone" do
|
51
|
+
expect(Object.new).not_to respond_to(:diff)
|
52
|
+
end
|
53
|
+
end
|
42
54
|
end
|