has_versions 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/has_versions.gemspec +1 -1
- data/lib/has_versions/version/diff.rb +12 -14
- data/test/has_versions/version/diff_test.rb +7 -11
- metadata +2 -2
data/has_versions.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module HasVersions
|
2
2
|
module Version
|
3
3
|
module Diff
|
4
|
-
def diff(
|
5
|
-
diff_fetch(
|
6
|
-
|
4
|
+
def diff(other = parent)
|
5
|
+
diff_fetch(other) do
|
6
|
+
other_snapshot = other.nil? ? {} : other.decoded_snapshot
|
7
7
|
|
8
8
|
output = {}
|
9
9
|
decoded_snapshot.each do |attribute, new_value|
|
10
|
-
|
10
|
+
other_value = other_snapshot[attribute]
|
11
11
|
|
12
|
-
if
|
13
|
-
output[attribute] = [
|
12
|
+
if other_value != new_value
|
13
|
+
output[attribute] = [other_value, new_value]
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,14 +18,12 @@ module HasVersions
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
diff.keys
|
21
|
+
def applied_modifications(other)
|
22
|
+
diff.keys - diff(other).keys
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
27
|
-
target.send(attribute) != decoded_snapshot[attribute]
|
28
|
-
end
|
25
|
+
def unused_modifications(other)
|
26
|
+
diff.keys & diff(other).keys
|
29
27
|
end
|
30
28
|
|
31
29
|
def decoded_snapshot
|
@@ -39,9 +37,9 @@ module HasVersions
|
|
39
37
|
end
|
40
38
|
|
41
39
|
private
|
42
|
-
def diff_fetch(
|
40
|
+
def diff_fetch(other)
|
43
41
|
@diff_cache ||= {}
|
44
|
-
@diff_cache[
|
42
|
+
@diff_cache[other] ||= yield
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
@@ -45,18 +45,14 @@ module HasVersions
|
|
45
45
|
assert_equal({'name' => [nil, 'decoded: bar'], 'weight' => [nil, 'decoded: 4.3']}, diff)
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def test_modifications
|
49
49
|
target = DiffRecord.new
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
target = DiffRecord.new(name: 'decoded: sam', color: 'decoded: green', weight: 'decoded: 129')
|
57
|
-
version = DiffRecord.version_model.new(target: target, snapshot: {'name' => 'joe', 'weight' => '129'})
|
58
|
-
|
59
|
-
assert_equal ['name'], version.different_attributes
|
50
|
+
parent = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'green', 'name' => 'joe', 'weight' => '50'})
|
51
|
+
version = DiffRecord.version_model.new(target: target, parent: parent, snapshot: {'color' => 'green', 'name' => 'sam', 'weight' => '129'})
|
52
|
+
other = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'blue', 'name' => 'sam', 'weight' => '100'})
|
53
|
+
|
54
|
+
assert_equal ['name'], version.applied_modifications(other)
|
55
|
+
assert_equal ['weight'], version.unused_modifications(other)
|
60
56
|
end
|
61
57
|
|
62
58
|
def test_decoded_snapshot
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|