17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/strokedb/sync/diff.rb', line 17
def self.diff(from, to)
unless from.class == to.class
to
else
case to
when /@##{UUID_RE}/, /@##{UUID_RE}.#{VERSION_RE}/
to
when Array, String
::Diff::LCS.diff(from, to).map do |d|
d.map do |change|
change.to_a
end
end
when Hash
::Diff::LCS.diff(from.sort_by{|e| e.to_s}, to.sort_by{|e| e.to_s}).map do |d|
d.map do |change|
[change.to_a.first, {change.to_a.last.first => change.to_a.last.last}]
end
end
else
to
end
end
end
|