paper_trail-hashdiff 0.0.6 → 0.1.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 +4 -4
- data/lib/paper_trail_hashdiff.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 251dd60eb103f5d4a523182092e1f3210d4fdaded0c05f32bec6306bc5ee8f31
|
4
|
+
data.tar.gz: 2a339767c1988bac2dd544800c37dabc0dce7fa591027ecb31e14b7ca4a06fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0598ff96236088341b5679b4540157dce805c61943c344f159fb63c48f7802c8003ddc08de086361b24c69a48a1523df35df70dc4017e6ff7b6e3d96a37e63f
|
7
|
+
data.tar.gz: 23e0be45dd69f7483cf1c8feb7d947d103d7c17d3143faec4e590bdabf1132a6b68107ee55ff4635df8a51546284d8df6bfba933ff4d43fdb782291f6fd284fd
|
data/lib/paper_trail_hashdiff.rb
CHANGED
@@ -3,10 +3,24 @@
|
|
3
3
|
# Allows storing only incremental changes in the object_changes column
|
4
4
|
# Uses HashDiff (https://github.com/liufengyun/hashdiff)
|
5
5
|
class PaperTrailHashDiff
|
6
|
+
attr_reader :only_objects
|
7
|
+
|
8
|
+
def initialize(only_objects: false)
|
9
|
+
@only_objects = only_objects
|
10
|
+
end
|
11
|
+
|
6
12
|
def diff(changes)
|
7
13
|
diff_changes = {}
|
8
14
|
changes.each do |field, value_changes|
|
9
|
-
|
15
|
+
if (
|
16
|
+
!only_objects ||
|
17
|
+
(value_changes[0] && (value_changes[0].is_a?(Hash) || value_changes[0].is_a?(Array))) ||
|
18
|
+
(value_changes[1] && (value_changes[1].is_a?(Hash) || value_changes[1].is_a?(Array)))
|
19
|
+
)
|
20
|
+
diff_changes[field] = Hashdiff.diff(value_changes[0], value_changes[1], array_path: true)
|
21
|
+
else
|
22
|
+
diff_changes[field] = value_changes
|
23
|
+
end
|
10
24
|
end
|
11
25
|
diff_changes
|
12
26
|
end
|