yesterday 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- unless @made_changes[compare_with_version_number]
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[compare_with_version_number] = VersionedObjectCreator.new(diff).to_object
37
+ @made_changes = VersionedObjectCreator.new(diff).to_object
40
38
  end
41
39
 
42
- @made_changes[compare_with_version_number]
40
+ @made_changes
43
41
  end
44
42
 
45
43
  private
@@ -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 != '_event'
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] ||= []
@@ -94,6 +94,7 @@ module Yesterday
94
94
  private
95
95
 
96
96
  def serialize_current_state
97
+ reload
97
98
  Versioning.create_changeset_for self
98
99
  invalidate_cached_versioning
99
100
  end
@@ -1,3 +1,3 @@
1
1
  module Yesterday
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
@@ -9,6 +9,10 @@ module Yesterday
9
9
  diff.first
10
10
  end
11
11
 
12
+ def modified?
13
+ current != previous
14
+ end
15
+
12
16
  def to_s
13
17
  current.to_s
14
18
  end
@@ -5,12 +5,8 @@ module Yesterday
5
5
  attributes['id']
6
6
  end
7
7
 
8
- def method_missing(method, *arguments, &block)
9
- if attributes.has_key?(method.to_s)
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
@@ -25,8 +25,6 @@ module Yesterday
25
25
  VersionedObjectCreator.new(diff).to_object
26
26
  end
27
27
 
28
- private
29
-
30
28
  def changeset_for(version_number, object)
31
29
  Changeset.for_changed_object(object).version(version_number).first
32
30
  end
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
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: