yesterday 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yesterday/changeset.rb +5 -7
- data/lib/yesterday/differ.rb +6 -2
- data/lib/yesterday/model.rb +1 -0
- data/lib/yesterday/version.rb +1 -1
- data/lib/yesterday/versioned_attribute.rb +4 -0
- data/lib/yesterday/versioned_object.rb +14 -6
- data/lib/yesterday/versioning.rb +0 -2
- data/yesterday.gemspec +1 -1
- metadata +4 -4
data/lib/yesterday/changeset.rb
CHANGED
@@ -27,19 +27,17 @@ module Yesterday
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def made_changes
|
30
|
-
@made_changes
|
30
|
+
unless @made_changes
|
31
|
+
compare_version_number ||= version_number > 1 ? (version_number - 1) : 1
|
31
32
|
|
32
|
-
|
33
|
-
compare_with_version_number ||= version_number > 1 ? (version_number - 1) : 1
|
34
|
-
|
35
|
-
from_attributes = changeset_for(compare_with_version_number, changed_object).object_attributes
|
33
|
+
from_attributes = Versioning.changeset_for(compare_version_number, changed_object).object_attributes
|
36
34
|
to_attributes = object_attributes
|
37
35
|
diff = Differ.new(from_attributes, to_attributes).diff
|
38
36
|
|
39
|
-
@made_changes
|
37
|
+
@made_changes = VersionedObjectCreator.new(diff).to_object
|
40
38
|
end
|
41
39
|
|
42
|
-
@made_changes
|
40
|
+
@made_changes
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
data/lib/yesterday/differ.rb
CHANGED
@@ -7,6 +7,10 @@ module Yesterday
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
+
def ignored_attributes
|
11
|
+
%w(updated_at created_at id _event)
|
12
|
+
end
|
13
|
+
|
10
14
|
def diff_object(from, to)
|
11
15
|
diff = diff_attributes(from, to)
|
12
16
|
|
@@ -25,7 +29,7 @@ module Yesterday
|
|
25
29
|
if attribute == 'id'
|
26
30
|
diff[attribute] = old_value
|
27
31
|
|
28
|
-
elsif !old_value.is_a?(Array) && attribute
|
32
|
+
elsif !old_value.is_a?(Array) && !ignored_attributes.include?(attribute)
|
29
33
|
new_value = to[attribute]
|
30
34
|
diff[attribute] = [old_value, new_value]
|
31
35
|
diff['_event'] = 'modified' if old_value != new_value
|
@@ -44,7 +48,7 @@ module Yesterday
|
|
44
48
|
new_objects = to[attribute]
|
45
49
|
|
46
50
|
old_objects.each do |old_object|
|
47
|
-
new_object = find_object(new_objects, old_object['id'])
|
51
|
+
new_object = find_object(new_objects, old_object['id']) if new_objects
|
48
52
|
|
49
53
|
if new_object
|
50
54
|
diff[attribute] ||= []
|
data/lib/yesterday/model.rb
CHANGED
data/lib/yesterday/version.rb
CHANGED
@@ -5,12 +5,8 @@ module Yesterday
|
|
5
5
|
attributes['id']
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
attributes[method.to_s]
|
11
|
-
else
|
12
|
-
super
|
13
|
-
end
|
8
|
+
def event
|
9
|
+
attributes['_event'] || 'unmodified'
|
14
10
|
end
|
15
11
|
|
16
12
|
def modified?
|
@@ -25,10 +21,22 @@ module Yesterday
|
|
25
21
|
attributes['_event'] && attributes['_event'] == 'destroyed'
|
26
22
|
end
|
27
23
|
|
24
|
+
def touched?
|
25
|
+
modified? || created? || destroyed?
|
26
|
+
end
|
27
|
+
|
28
28
|
def unmodified?
|
29
29
|
!attributes.has_key?('_event')
|
30
30
|
end
|
31
31
|
|
32
|
+
def method_missing(method, *arguments, &block)
|
33
|
+
if attributes.has_key?(method.to_s)
|
34
|
+
attributes[method.to_s]
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
32
40
|
end
|
33
41
|
|
34
42
|
end
|
data/lib/yesterday/versioning.rb
CHANGED
data/yesterday.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Diederick Lawson"]
|
10
10
|
s.email = ["webmaster@altovista.nl"]
|
11
|
-
s.homepage = ""
|
11
|
+
s.homepage = "http://www.altovista.nl"
|
12
12
|
s.summary = "Track history in your active record models"
|
13
13
|
s.description = "Track history and view any made changes in your active record models"
|
14
14
|
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yesterday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 5
|
9
|
+
version: "0.5"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Diederick Lawson
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- spec/yesterday_model_spec.rb
|
97
97
|
- yesterday.gemspec
|
98
98
|
has_rdoc: true
|
99
|
-
homepage:
|
99
|
+
homepage: http://www.altovista.nl
|
100
100
|
licenses: []
|
101
101
|
|
102
102
|
post_install_message:
|