rexle-diff 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -3
- data/lib/rexle-diff.rb +61 -18
- metadata +7 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b01a429faca38a0012c0fbacba964d73b8b446f0
|
4
|
+
data.tar.gz: 35abca30022f63e2050c08386ede1fadc1d3dc8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c9545684ed7caa9942949e001d86e9f48a951a377c348ee61a253f35b318555d8f185665f318cb850698fab9f81ef554726633bba672416d59fbd47a187ad3a
|
7
|
+
data.tar.gz: 3529f4691329569af9a02a13c69e8b0b2b0c783eed717770cf34997535d1a1bc5e1eeeefdf7fd63c3221d1302b8ca71286c9bdd39d31b1abbb8bd9794b4d009c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
��
|
2
|
-
|
3
|
-
Lu(-u������2�z�9���i��άlj��ho�+���'�RUH�B�=����`D4�Q���7��ġ��G������0Α%��rc7a�a$(���]���zD�� !�
|
1
|
+
�'�tg��(J��S�Љ�7m�a��nW*�GD�&��M�-�SȎ�r��+���^�6�
|
2
|
+
�͎� �0$DDe�A��t]�.��z#��Ӄ��Oh���J�*�-A{W����k�c���CpY`>��3L6q+�NH�,�=��Wb�9?B��5����[̾�e<�?X��]��*�ʮm�"�3]fڝ\d&֍���6��*o;nd?F��l;���ޤ�
|
data/lib/rexle-diff.rb
CHANGED
@@ -6,14 +6,69 @@ require 'rexle'
|
|
6
6
|
require 'fuzzy_match'
|
7
7
|
|
8
8
|
|
9
|
+
class Rexle::Element
|
10
|
+
|
11
|
+
def hashed() @hash end
|
12
|
+
def hashed=(num) @hash = num end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
9
17
|
class RexleDiff
|
18
|
+
|
19
|
+
class HashedDoc
|
20
|
+
|
21
|
+
def initialize(node)
|
22
|
+
|
23
|
+
@node = node
|
24
|
+
@node.hashed = hash(node) + hashit(node).inject(:+)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_doc()
|
29
|
+
@node
|
30
|
+
end
|
31
|
+
|
32
|
+
def hash(element)
|
33
|
+
|
34
|
+
attributes = element.attributes.clone
|
35
|
+
%i(created last_modified).each {|x| attributes.delete x}
|
36
|
+
[element.name, attributes, element.text.to_s.strip].hash
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def hashit(node)
|
41
|
+
|
42
|
+
a = node.elements.map do |element|
|
43
|
+
|
44
|
+
row = hash element
|
45
|
+
|
46
|
+
if element.has_elements?
|
47
|
+
r = hashit(element)
|
48
|
+
sum = row + r.inject(:+)
|
49
|
+
element.hashed = sum
|
50
|
+
sum
|
51
|
+
else
|
52
|
+
element.hashed = row
|
53
|
+
row
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
10
61
|
|
62
|
+
|
11
63
|
attr_reader :to_doc
|
12
64
|
|
13
65
|
def initialize(source1, source2, fuzzy_match: false)
|
14
66
|
|
15
67
|
@fuzzy_match = fuzzy_match
|
16
|
-
|
68
|
+
|
69
|
+
doc1, doc2 = HashedDoc.new(Rexle.new(source1).root).to_doc,
|
70
|
+
HashedDoc.new(Rexle.new(source2).root).to_doc
|
71
|
+
|
17
72
|
compare(doc1.root, doc2.root)
|
18
73
|
|
19
74
|
@to_doc = doc2
|
@@ -21,7 +76,6 @@ class RexleDiff
|
|
21
76
|
|
22
77
|
private
|
23
78
|
|
24
|
-
|
25
79
|
|
26
80
|
# Returns an array of indexes of the nodes from the newer document which
|
27
81
|
# have been added or changed
|
@@ -30,7 +84,7 @@ class RexleDiff
|
|
30
84
|
|
31
85
|
list1 = hxlist.map.with_index {|x,i| x + i}
|
32
86
|
list2 = hxlist2.map.with_index {|x,i| x + i}
|
33
|
-
|
87
|
+
|
34
88
|
added_or_changed = list2 - list1
|
35
89
|
indexes = added_or_changed.map {|x| list2.index x}
|
36
90
|
|
@@ -48,6 +102,7 @@ class RexleDiff
|
|
48
102
|
# elements which may have been modified are also
|
49
103
|
# added to the added_indexes list
|
50
104
|
added_or_changed_indexes = added(hxlist, hxlist2)
|
105
|
+
|
51
106
|
added_indexes, updated_indexes = @fuzzy_match ? \
|
52
107
|
fuzzy_match(added_or_changed_indexes, node, node2) : \
|
53
108
|
[added_or_changed_indexes, []]
|
@@ -66,7 +121,7 @@ class RexleDiff
|
|
66
121
|
deleted_indexes = deleted(hxlist, hxlist2)
|
67
122
|
|
68
123
|
unchanged_indexes = unchanged(hxlist, hxlist2)
|
69
|
-
|
124
|
+
|
70
125
|
unchanged_indexes.each do |i, i2|
|
71
126
|
|
72
127
|
compare(node.elements[i+1], node2.elements[i2+1]) if node\
|
@@ -124,20 +179,8 @@ class RexleDiff
|
|
124
179
|
#
|
125
180
|
def hashedxml(node)
|
126
181
|
|
127
|
-
node.elements.map
|
128
|
-
|
129
|
-
attributes = element.attributes.clone
|
130
|
-
|
131
|
-
# Although attribute last_modified isn't used by rexle-diff it is
|
132
|
-
# created by Dynarex whenever a record is created or updated.
|
133
|
-
# This would of course cause the record to be flagged as changed even
|
134
|
-
# when the element value itself hashn't changed.
|
135
|
-
#
|
136
|
-
%i(created last_modified).each {|x| attributes.delete x}
|
137
|
-
x = element.elements.length > 0 ? '' : 0
|
138
|
-
[element.name, attributes, element.text.to_s.strip, x].hash
|
139
|
-
|
140
|
-
end
|
182
|
+
node.elements.map &:hashed
|
183
|
+
|
141
184
|
end
|
142
185
|
|
143
186
|
# Returns an array of indexes from both original and new nodes which
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexle-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -39,20 +39,20 @@ dependencies:
|
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
42
|
+
version: '1.4'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 1.4.1
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1.
|
52
|
+
version: '1.4'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.4.1
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: fuzzy_match
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,5 +103,6 @@ rubyforge_project:
|
|
103
103
|
rubygems_version: 2.5.1
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
|
-
summary:
|
106
|
+
summary: Compares XML and returns the latest XML with changes identified by datetime
|
107
|
+
stamps in the attributes.
|
107
108
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|