hash_deep_diff 0.3.2 → 0.3.3
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/README.md +13 -10
- data/lib/hash_deep_diff/delta/acts_as_delta.rb +3 -0
- data/lib/hash_deep_diff/delta/inner.rb +13 -25
- data/lib/hash_deep_diff/delta/left.rb +13 -7
- data/lib/hash_deep_diff/delta/right.rb +13 -7
- data/lib/hash_deep_diff/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3724394c10b36b7537f35bce5c7f079cae0ee3344062a78bdfe7256363624b
|
4
|
+
data.tar.gz: e9baa112b03013b91f75ebea9f243a0a6d51ca746ca8c8e66ea6fa38803198fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7393bb437eddfb8e0ed66d4eba3b4135e221c7c2262df14aa4509dba98345c4766b598bd3c3f11f311c84b25b4f9f0b2bca3dfc5083c023c87c582fa607761a
|
7
|
+
data.tar.gz: 57708513050ac1e63c0ce64b9650e0ae0e3128127cbb4dfc5b248cc3caca3267cbd26bed7b939be4413c11f1a7038f5503aef143119a09e336cc113324ae182a
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# HashDeepDiff
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Find the exact difference between two Hash objects and build a report to visualize it
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -21,15 +19,20 @@ Or install it yourself as:
|
|
21
19
|
$ gem install hash_deep_diff
|
22
20
|
|
23
21
|
## Usage
|
22
|
+
Basic example
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
```ruby
|
25
|
+
left = { a: :a }
|
26
|
+
right = { a: :b }
|
30
27
|
|
31
|
-
|
28
|
+
HashDeepDiff::Comparison.new(left, right).report
|
29
|
+
```
|
30
|
+
```diff
|
31
|
+
- left[a] = a
|
32
|
+
+ right[a] = b
|
33
|
+
```
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at [bpohoriletz](https://github.com/bpohoriletz/hash_deep_diff).
|
38
|
+
|
@@ -23,6 +23,7 @@ module HashDeepDiff
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# TOFIX poor naming
|
26
|
+
# overrides parameter in initializer
|
26
27
|
def path
|
27
28
|
@prefix + [@delta.keys.first]
|
28
29
|
end
|
@@ -54,9 +55,11 @@ module HashDeepDiff
|
|
54
55
|
# TOFIX this may prohibit usage of hashes with Array keys
|
55
56
|
if path.respond_to?(:to_ary)
|
56
57
|
@delta = { path[-1] => value }
|
58
|
+
@value = value
|
57
59
|
@prefix = path[0..-2]
|
58
60
|
else
|
59
61
|
@delta = { path => value }
|
62
|
+
@value = value
|
60
63
|
@prefix = []
|
61
64
|
end
|
62
65
|
end
|
@@ -11,29 +11,17 @@ module HashDeepDiff
|
|
11
11
|
include Delta::ActsAsDelta
|
12
12
|
|
13
13
|
def to_str
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
@delta.values.first.keys.map do |key|
|
27
|
-
self.class.new(path: path + [key], value: @delta.values.first[key])
|
28
|
-
end.join("\n").strip
|
29
|
-
end
|
30
|
-
else
|
31
|
-
lines = <<~Q
|
32
|
-
-left#{diff_prefix} = #{left}
|
33
|
-
+right#{diff_prefix} = #{right}
|
34
|
-
Q
|
35
|
-
lines.strip
|
36
|
-
end
|
14
|
+
return diff unless complex?
|
15
|
+
|
16
|
+
HashDeepDiff::Comparison.new(left, right, path).report
|
17
|
+
end
|
18
|
+
|
19
|
+
def diff
|
20
|
+
lines = <<~Q
|
21
|
+
-left#{diff_prefix} = #{left}
|
22
|
+
+right#{diff_prefix} = #{right}
|
23
|
+
Q
|
24
|
+
lines.strip
|
37
25
|
end
|
38
26
|
|
39
27
|
def complex?
|
@@ -41,11 +29,11 @@ module HashDeepDiff
|
|
41
29
|
end
|
42
30
|
|
43
31
|
def left
|
44
|
-
@
|
32
|
+
@value[:left]
|
45
33
|
end
|
46
34
|
|
47
35
|
def right
|
48
|
-
@
|
36
|
+
@value[:right]
|
49
37
|
end
|
50
38
|
end
|
51
39
|
end
|
@@ -11,13 +11,19 @@ module HashDeepDiff
|
|
11
11
|
include Delta::ActsAsDelta
|
12
12
|
|
13
13
|
def to_str
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
return "+left#{diff_prefix} = #{left}" unless left.respond_to?(:to_hash)
|
15
|
+
|
16
|
+
left.keys.map do |key|
|
17
|
+
self.class.new(path: path + [key], value: left[key])
|
18
|
+
end.join("\n").strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def left
|
22
|
+
@value
|
23
|
+
end
|
24
|
+
|
25
|
+
def right
|
26
|
+
nil
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -11,13 +11,19 @@ module HashDeepDiff
|
|
11
11
|
include Delta::ActsAsDelta
|
12
12
|
|
13
13
|
def to_str
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
return "-left#{diff_prefix} = #{right}" unless right.respond_to?(:to_hash)
|
15
|
+
|
16
|
+
right.keys.map do |key|
|
17
|
+
self.class.new(path: path + [key], value: right[key])
|
18
|
+
end.join("\n").strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def left
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def right
|
26
|
+
@value
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_deep_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bohdan Pohorilets
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|