yesterday 1.0.rc1 → 1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/lib/generators/yesterday/templates/create_changesets.rb +3 -0
- data/lib/yesterday.rb +1 -1
- data/lib/yesterday/{changeset.rb → changeset_base.rb} +25 -20
- data/lib/yesterday/model.rb +12 -2
- data/lib/yesterday/version.rb +1 -1
- data/lib/yesterday/versioning.rb +3 -3
- data/spec/models.rb +7 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/yesterday_model_spec.rb +2 -2
- metadata +75 -45
data/README.rdoc
CHANGED
@@ -14,9 +14,17 @@ And then run the generator in your Rails 3 project:
|
|
14
14
|
|
15
15
|
== Use tracking in your models
|
16
16
|
|
17
|
+
First create model that will hold your changesets:
|
18
|
+
|
19
|
+
class Changeset < ActiveRecord::Base
|
20
|
+
include Yesterday::ChangesetBase
|
21
|
+
end
|
22
|
+
|
23
|
+
Now assign the models you want to track:
|
24
|
+
|
17
25
|
class Contact < ActiveRecord::Base
|
18
26
|
has_many :addresses
|
19
|
-
track_changes
|
27
|
+
track_changes :with => :changesets
|
20
28
|
end
|
21
29
|
|
22
30
|
class Address < ActiveRecord::Base
|
@@ -8,6 +8,9 @@ class CreateChangesets < ActiveRecord::Migration
|
|
8
8
|
t.datetime :created_at
|
9
9
|
t.datetime :updated_at
|
10
10
|
end
|
11
|
+
|
12
|
+
create_index :changesets, [ :changed_object_id, :changed_object_type ]
|
13
|
+
create_index :changesets, [ :changed_object_id, :changed_object_type, :version_number ]
|
11
14
|
end
|
12
15
|
|
13
16
|
def self.down
|
data/lib/yesterday.rb
CHANGED
@@ -1,25 +1,11 @@
|
|
1
1
|
module Yesterday
|
2
|
-
|
2
|
+
module ChangesetBase
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.version(version_number)
|
10
|
-
where(:version_number => version_number)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.for_changed_object(object)
|
14
|
-
where(:changed_object_type => object.class.to_s, :changed_object_id => object.id)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.last_for(object)
|
18
|
-
for_changed_object(object).order('created_at DESC').first
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.version_number_for(object)
|
22
|
-
last_for(object).try(:version_number) || 0
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.before_create :determine_version_number, :determine_object_attributes
|
7
|
+
base.belongs_to :changed_object, :polymorphic => true
|
8
|
+
base.serialize :object_attributes
|
23
9
|
end
|
24
10
|
|
25
11
|
def object
|
@@ -50,5 +36,24 @@ module Yesterday
|
|
50
36
|
self.object_attributes = Yesterday::Serializer.new(changed_object).to_hash
|
51
37
|
end
|
52
38
|
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
def version(version_number)
|
42
|
+
where(:version_number => version_number)
|
43
|
+
end
|
44
|
+
|
45
|
+
def for_changed_object(object)
|
46
|
+
where(:changed_object_type => object.class.to_s, :changed_object_id => object.id)
|
47
|
+
end
|
48
|
+
|
49
|
+
def last_for(object)
|
50
|
+
for_changed_object(object).order('created_at DESC').first
|
51
|
+
end
|
52
|
+
|
53
|
+
def version_number_for(object)
|
54
|
+
last_for(object).try(:version_number) || 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
53
58
|
end
|
54
59
|
end
|
data/lib/yesterday/model.rb
CHANGED
@@ -46,11 +46,21 @@ module Yesterday
|
|
46
46
|
@tracked_attributes || []
|
47
47
|
end
|
48
48
|
|
49
|
+
def changeset_model
|
50
|
+
@changeset_model
|
51
|
+
end
|
52
|
+
|
53
|
+
def changeset_klass
|
54
|
+
changeset_model.classify.constantize
|
55
|
+
end
|
56
|
+
|
49
57
|
def track_changes(options = {})
|
50
|
-
|
58
|
+
with = options[:with] || :changeset
|
59
|
+
@changeset_model = with.to_s
|
51
60
|
|
61
|
+
send :include, InstanceMethods
|
52
62
|
after_save :serialize_current_state
|
53
|
-
exclude_tracking_for :associations =>
|
63
|
+
exclude_tracking_for :associations => with.to_s.pluralize.to_sym
|
54
64
|
end
|
55
65
|
|
56
66
|
def version(version_number)
|
data/lib/yesterday/version.rb
CHANGED
data/lib/yesterday/versioning.rb
CHANGED
@@ -2,11 +2,11 @@ module Yesterday
|
|
2
2
|
class Versioning
|
3
3
|
class << self
|
4
4
|
def create_changeset_for(object)
|
5
|
-
|
5
|
+
object.class.changeset_klass.create :changed_object => object
|
6
6
|
end
|
7
7
|
|
8
8
|
def changesets_for(object)
|
9
|
-
|
9
|
+
object.class.changeset_klass.for_changed_object(object)
|
10
10
|
end
|
11
11
|
|
12
12
|
def current_version_number_for(object)
|
@@ -26,7 +26,7 @@ module Yesterday
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def changeset_for(version_number, object)
|
29
|
-
|
29
|
+
object.class.changeset_klass.for_changed_object(object).version(version_number).first
|
30
30
|
end
|
31
31
|
|
32
32
|
def object_attributes_for(version_number, object)
|
data/spec/models.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
class Changeset < ActiveRecord::Base
|
2
|
+
include Yesterday::ChangesetBase
|
3
|
+
end
|
4
|
+
|
1
5
|
class Report < ActiveRecord::Base
|
2
6
|
has_many :contacts
|
3
7
|
has_many :companies
|
4
8
|
|
5
|
-
track_changes
|
9
|
+
track_changes :with => :changesets
|
6
10
|
end
|
7
11
|
|
8
12
|
class Contact < ActiveRecord::Base
|
9
13
|
has_and_belongs_to_many :addresses
|
10
14
|
end
|
11
15
|
|
12
|
-
class Address < ActiveRecord::Base
|
13
|
-
end
|
16
|
+
class Address < ActiveRecord::Base; end
|
14
17
|
|
15
18
|
class Company < ActiveRecord::Base
|
16
19
|
has_and_belongs_to_many :addresses
|
17
|
-
|
18
|
-
track_changes
|
20
|
+
track_changes :with => :changesets
|
19
21
|
exclude_tracking_for :attributes => [:created_at, :updated_at]
|
20
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,9 +10,9 @@ describe Yesterday::Model do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should create a new changeset when saved' do
|
13
|
-
|
13
|
+
Changeset.count.should == 0
|
14
14
|
Report.create :description => 'bar'
|
15
|
-
|
15
|
+
Changeset.count.should == 1
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should return all related changesets' do
|
metadata
CHANGED
@@ -1,56 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yesterday
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15424241
|
5
5
|
prerelease: 4
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- rc
|
10
|
+
- 2
|
11
|
+
version: 1.0.rc2
|
6
12
|
platform: ruby
|
7
|
-
authors:
|
13
|
+
authors:
|
8
14
|
- Diederick Lawson
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
|
19
|
+
date: 2011-09-20 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: rspec
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
22
33
|
type: :development
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: sqlite3
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
33
47
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
37
50
|
name: rails
|
38
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
53
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
44
61
|
type: :runtime
|
45
|
-
|
46
|
-
version_requirements: *70215422678280
|
62
|
+
version_requirements: *id003
|
47
63
|
description: Track history and view any made changes in your active record models
|
48
|
-
email:
|
64
|
+
email:
|
49
65
|
- webmaster@altovista.nl
|
50
66
|
executables: []
|
67
|
+
|
51
68
|
extensions: []
|
69
|
+
|
52
70
|
extra_rdoc_files: []
|
53
|
-
|
71
|
+
|
72
|
+
files:
|
54
73
|
- .gitignore
|
55
74
|
- Gemfile
|
56
75
|
- README.rdoc
|
@@ -58,7 +77,7 @@ files:
|
|
58
77
|
- lib/generators/yesterday/install_generator.rb
|
59
78
|
- lib/generators/yesterday/templates/create_changesets.rb
|
60
79
|
- lib/yesterday.rb
|
61
|
-
- lib/yesterday/
|
80
|
+
- lib/yesterday/changeset_base.rb
|
62
81
|
- lib/yesterday/differ.rb
|
63
82
|
- lib/yesterday/historical_value.rb
|
64
83
|
- lib/yesterday/model.rb
|
@@ -79,29 +98,40 @@ files:
|
|
79
98
|
- yesterday.gemspec
|
80
99
|
homepage: http://www.altovista.nl
|
81
100
|
licenses: []
|
101
|
+
|
82
102
|
post_install_message:
|
83
103
|
rdoc_options: []
|
84
|
-
|
104
|
+
|
105
|
+
require_paths:
|
85
106
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
108
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
117
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
118
|
+
requirements:
|
119
|
+
- - ">"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 25
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 3
|
125
|
+
- 1
|
97
126
|
version: 1.3.1
|
98
127
|
requirements: []
|
128
|
+
|
99
129
|
rubyforge_project: yesterday
|
100
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.7
|
101
131
|
signing_key:
|
102
132
|
specification_version: 3
|
103
133
|
summary: Track history in your active record models
|
104
|
-
test_files:
|
134
|
+
test_files:
|
105
135
|
- spec/database.yml
|
106
136
|
- spec/differ_spec.rb
|
107
137
|
- spec/models.rb
|