hash_diff 0.6.0 → 0.6.1
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/lib/hash_diff/comparison.rb +14 -13
- data/lib/hash_diff/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTU2MzRlMGI1NGI2MmExNjkzMTU2NDUwYWE4MzQwNzI0MGJlNGE0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTZiYTQ5MjcxZDU1MzUyYWJhNjllZDVhYWZhYzIxMjdlMjMwM2VkNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzE2YTg3YzIxMjZjNmJiMjk4M2VkN2MyNmQ0ZjI0MWNkYzJmYWFiNDUwMjdl
|
10
|
+
ZWU4ZTY1ZjA1YTY2OTU4OTk4MDhjM2FiOTJiY2YwMzVjMDBkOWI4ZjZlNzlj
|
11
|
+
MWU5MjFhZGZkZTc0NmNmNTI5MmIxZTg2NWJkOTI0NzgxNTNmMGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWYzZDYwZDZkNTI3OWQ3YmZjNmVkYTVlNWYyM2ZlMDAxY2U0ZjhhMzNjYjFi
|
14
|
+
ZDBmM2M3ZTNlYTM3MmRjNzVkZTc0YzBiYTE5MWZkMjIzNzk2ZTIzNTAyYWEw
|
15
|
+
ZGUwNDgxNTI2ZjlkMWU0OGJmOGRlMWUxZmNkN2I2YTllMTA3ZTE=
|
data/lib/hash_diff/comparison.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
1
|
module HashDiff
|
4
2
|
class Comparison < Struct.new(:left, :right)
|
5
3
|
|
6
4
|
def diff
|
7
|
-
@side ||= :both
|
8
5
|
@diff ||= differences(left, right)
|
9
6
|
end
|
10
7
|
|
11
8
|
def left_diff
|
12
|
-
@
|
9
|
+
@concern = :left
|
13
10
|
@left_diff ||= differences(left, right)
|
14
11
|
end
|
15
12
|
|
16
13
|
def right_diff
|
17
|
-
@
|
14
|
+
@concern = :right
|
18
15
|
@right_diff ||= differences(left, right)
|
19
16
|
end
|
20
17
|
|
21
18
|
private
|
22
19
|
|
20
|
+
def concern
|
21
|
+
@concern ||= :both
|
22
|
+
end
|
23
|
+
|
23
24
|
def clone(left, right)
|
24
25
|
self.dup.tap do |inst|
|
25
26
|
inst.left = left
|
@@ -28,7 +29,7 @@ module HashDiff
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def differences(left, right)
|
31
|
-
combined_attribute_keys
|
32
|
+
combined_attribute_keys.reduce({}, &reduction_strategy)
|
32
33
|
end
|
33
34
|
|
34
35
|
def reduction_strategy(opts={})
|
@@ -38,32 +39,32 @@ module HashDiff
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
def combined_attribute_keys
|
42
|
+
def combined_attribute_keys
|
42
43
|
(left.keys + right.keys).uniq
|
43
44
|
end
|
44
45
|
|
45
46
|
def equal?(key)
|
46
|
-
left
|
47
|
+
left[key] == right[key]
|
47
48
|
end
|
48
49
|
|
49
50
|
def hash?(value)
|
50
51
|
value.is_a? Hash
|
51
52
|
end
|
52
53
|
|
53
|
-
def
|
54
|
+
def comparable?(key)
|
54
55
|
hash?(left[key]) and hash?(right[key])
|
55
56
|
end
|
56
57
|
|
57
58
|
def report(key)
|
58
|
-
if
|
59
|
+
if comparable?(key)
|
59
60
|
clone(left[key], right[key]).diff
|
60
61
|
else
|
61
|
-
|
62
|
+
report_concern(key)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
-
case
|
66
|
+
def report_concern(key)
|
67
|
+
case concern
|
67
68
|
when :left then right[key]
|
68
69
|
when :right then left[key]
|
69
70
|
when :both then [left[key], right[key]]
|
data/lib/hash_diff/version.rb
CHANGED