has_versions 0.9.5 → 0.9.6
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/has_versions.gemspec +1 -1
- data/lib/has_versions.rb +1 -1
- data/lib/has_versions/record/attributes.rb +11 -12
- data/lib/has_versions/record/orm/cassandra_object.rb +0 -4
- data/lib/has_versions/record/reset.rb +1 -1
- data/lib/has_versions/version/diff.rb +1 -1
- data/test/has_versions/record/reset_test.rb +1 -1
- data/test/has_versions/version/diff_test.rb +2 -2
- data/test/support/test_model.rb +7 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae7b9788e9ca7a3aa879653aee867fc8c8d2fb1e
|
4
|
+
data.tar.gz: 584cf98bfe7f16a6a6e760166b11c98ecf51db65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5635cbc68cd4d6c413ac818ef22502442b5be17a79f3e64c546bcebe217804eab69fdde1e4c7a54b7f17ae5b0528ff01a284b180353724d85b325b064a5e1f05
|
7
|
+
data.tar.gz: e9d359872eb49c5311693f957a1744b2edef516dc311c576f599e9e2ce935924e9ee4426eaf2fa576ae8a24992bf09b547bf428a27bb6025354d3b5b0d1b4f20
|
data/has_versions.gemspec
CHANGED
data/lib/has_versions.rb
CHANGED
@@ -7,29 +7,28 @@ module HasVersions
|
|
7
7
|
def versioned_attributes
|
8
8
|
versioning_configuration.attributes
|
9
9
|
end
|
10
|
+
|
11
|
+
def create_versioned_attributes(&block)
|
12
|
+
versioned_attributes.inject({}) do |memo, attribute|
|
13
|
+
if (value = block.call(attribute)).present?
|
14
|
+
memo[attribute] = versioning_encode_value(attribute, value)
|
15
|
+
end
|
16
|
+
memo
|
17
|
+
end
|
18
|
+
end
|
10
19
|
end
|
11
20
|
|
12
21
|
def versioned_attributes
|
13
|
-
create_versioned_attributes do |attribute|
|
22
|
+
self.class.create_versioned_attributes do |attribute|
|
14
23
|
self[attribute]
|
15
24
|
end
|
16
25
|
end
|
17
26
|
|
18
27
|
def versioned_attributes_was
|
19
|
-
create_versioned_attributes do |attribute|
|
28
|
+
self.class.create_versioned_attributes do |attribute|
|
20
29
|
send("#{attribute}_was")
|
21
30
|
end
|
22
31
|
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def create_versioned_attributes(&block)
|
26
|
-
self.class.versioned_attributes.inject({}) do |memo, attribute|
|
27
|
-
if (value = block.call(attribute)).present?
|
28
|
-
memo[attribute] = versioning_encode_value(attribute, value)
|
29
|
-
end
|
30
|
-
memo
|
31
|
-
end
|
32
|
-
end
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -13,7 +13,7 @@ module HasVersions
|
|
13
13
|
|
14
14
|
def reset!(version)
|
15
15
|
self.class.versioned_attributes.each do |attribute|
|
16
|
-
value = versioning_decode_value(attribute, version.snapshot[attribute])
|
16
|
+
value = self.class.versioning_decode_value(attribute, version.snapshot[attribute])
|
17
17
|
send("#{attribute}=", value)
|
18
18
|
end
|
19
19
|
self
|
@@ -30,7 +30,7 @@ module HasVersions
|
|
30
30
|
@decoded_snapshot ||= begin
|
31
31
|
decoded = {}
|
32
32
|
target.class.versioned_attributes.each do |attribute|
|
33
|
-
decoded[attribute] = target.versioning_decode_value(attribute, snapshot[attribute])#attribute.to_s#decode_attribute(attribute, snapshot[attribute])
|
33
|
+
decoded[attribute] = target.class.versioning_decode_value(attribute, snapshot[attribute])#attribute.to_s#decode_attribute(attribute, snapshot[attribute])
|
34
34
|
end
|
35
35
|
decoded
|
36
36
|
end
|
@@ -11,7 +11,7 @@ module HasVersions
|
|
11
11
|
versioning_configuration.attribute :name
|
12
12
|
versioning_configuration.attribute :weight
|
13
13
|
|
14
|
-
def versioning_decode_value(name, value)
|
14
|
+
def self.versioning_decode_value(name, value)
|
15
15
|
"decoded: #{value}"
|
16
16
|
end
|
17
17
|
end
|
@@ -50,7 +50,7 @@ module HasVersions
|
|
50
50
|
parent = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'green', 'name' => 'joe', 'weight' => '50'})
|
51
51
|
version = DiffRecord.version_model.new(target: target, parent: parent, snapshot: {'color' => 'green', 'name' => 'sam', 'weight' => '129'})
|
52
52
|
other = DiffRecord.version_model.new(target: target, snapshot: {'color' => 'blue', 'name' => 'sam', 'weight' => '100'})
|
53
|
-
|
53
|
+
|
54
54
|
assert_equal ['name'], version.applied_modifications(other)
|
55
55
|
assert_equal ['weight'], version.unused_modifications(other)
|
56
56
|
end
|
data/test/support/test_model.rb
CHANGED
@@ -10,16 +10,14 @@ class TestRecord
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
value
|
15
|
-
|
16
|
-
|
17
|
-
def versioning_decode_value(name, value)
|
18
|
-
value
|
19
|
-
end
|
13
|
+
class << self
|
14
|
+
def versioning_encode_value(name, value)
|
15
|
+
value.to_s
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
def versioning_decode_value(name, value)
|
19
|
+
value
|
20
|
+
end
|
23
21
|
end
|
24
22
|
|
25
23
|
def [](attribute)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Rodgers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|