hash_diff 0.6.3 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab2e595d5da98e49d516f5d7155b719b44ca7761
4
- data.tar.gz: e6cff1864bb75c22da07fb640ee9a63488f91b66
3
+ metadata.gz: 138f8fc905ed5caa8160dc05131bfd1d1f484908
4
+ data.tar.gz: 7bc15e4a8d6e0fa94bd1c4bc0f29d67e34ad7dc1
5
5
  SHA512:
6
- metadata.gz: a1535bd251d67c22d92f7a481a2ed747607d8af0190ec33d1f1d7e5d56d631f62368c5c2e06a4bd2ed21818532959d9df7815bb696b7d0cd9a32ead546d43871
7
- data.tar.gz: 204f6d43919ebc83820be81790251790787238940e16e90b3ca4eade052a576234134dc67e6993ec4494636a4f6b555e5316e70b8989c484342db9494818a260
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, use the following code snippet.
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
- class Hash
82
- def diff(right)
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 }
@@ -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
@@ -1,3 +1,3 @@
1
1
  module HashDiff
2
- VERSION = "0.6.3"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -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
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.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coding Zeal