laserlemon-vestal_versions 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +68 -4
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/vestal_versions.gemspec +2 -2
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,13 +1,77 @@
|
|
1
1
|
= vestal_versions
|
2
2
|
|
3
|
+
Finally, DRY ActiveRecord versioning!
|
4
|
+
|
5
|
+
technoweenie[http://github.com/technoweenie]'s <tt>acts_as_versioned</tt>[http://github.com/technoweenie/acts_as_versioned] was a great start, but it failed to keep up with ActiveRecord's introduction of dirty objects in version 2.1. Additionally, each versioned model needs its own versions table that duplicates most of the original table's columns. The versions table is then populated with records that often duplicate most of the original record's attributes. All in all, not very DRY at all.
|
6
|
+
|
7
|
+
<tt>simply_versioned</tt>[http://github.com/mmower/simply_versioned] by mmower[http://github.com/mmower] started to move in the right direction by removing a great deal of the duplication of acts_as_versioned. It requires only one versions table and no changes whatsoever to existing models. Its versions table stores all of the model attributes as a YAML hash in a single text column. But we could be DRYer!
|
8
|
+
|
9
|
+
<tt>vestal_versions</tt> keeps in the spirit of consolidating to one versions table, polymorphically associated with its parent models. But it goes one step further by storing a serialized hash of only the models' changes. Think modern version control systems. By traversing the record of changes, the models can be reverted to any point in time.
|
10
|
+
|
11
|
+
And that's just what <tt>vestal_versions</tt> does. Not only can a model be reverted to a previous version number but it can be reverted to a date or time!
|
12
|
+
|
3
13
|
== Installation
|
4
14
|
|
5
|
-
|
15
|
+
In <tt>environment.rb</tt>:
|
16
|
+
|
17
|
+
Rails::Initializer.run do |config|
|
18
|
+
config.gem 'laserlemon-vestal_versions', :lib => 'vestal_versions', :source => 'http://gems.github.com'
|
19
|
+
end
|
20
|
+
|
21
|
+
At your application root, run:
|
22
|
+
|
23
|
+
$ sudo rake gems:install
|
24
|
+
|
25
|
+
Next, generate and run the first and last versioning migration you'll ever need:
|
26
|
+
|
27
|
+
$ script/generate vestal_versions_migration
|
28
|
+
$ rake db:migrate
|
6
29
|
|
7
30
|
== Example
|
8
31
|
|
9
|
-
|
32
|
+
To version an ActiveRecord model, simply add <tt>versioned</tt> to you class like so:
|
33
|
+
|
34
|
+
class User < ActiveRecord::Base
|
35
|
+
versioned
|
36
|
+
|
37
|
+
validates_presence_of :first_name, :last_name
|
38
|
+
|
39
|
+
def name
|
40
|
+
"#{first_name} #{last_name}"
|
41
|
+
end
|
42
|
+
end
|
10
43
|
|
11
|
-
|
44
|
+
It's that easy! Now watch it in action...
|
12
45
|
|
13
|
-
|
46
|
+
>> u = User.create(:first_name => 'Steve', :last_name => 'Richert')
|
47
|
+
=> #<User first_name: "Steve", last_name: "Richert">
|
48
|
+
>> u.version
|
49
|
+
=> 1
|
50
|
+
>> u.update_attribute(:first_name, 'Stephen')
|
51
|
+
=> true
|
52
|
+
>> u.name
|
53
|
+
=> "Stephen Richert"
|
54
|
+
>> u.version
|
55
|
+
=> 2
|
56
|
+
>> u.revert_to(:first)
|
57
|
+
=> 1
|
58
|
+
>> u.name
|
59
|
+
=> "Steve Richert"
|
60
|
+
>> u.version
|
61
|
+
=> 1
|
62
|
+
>> u.save
|
63
|
+
=> true
|
64
|
+
>> u.version
|
65
|
+
=> 3
|
66
|
+
>> u.update_attribute(:last_name, 'Jobs')
|
67
|
+
=> true
|
68
|
+
>> u.name
|
69
|
+
=> "Steve Jobs"
|
70
|
+
>> u.version
|
71
|
+
=> 4
|
72
|
+
>> u.revert_to!(2)
|
73
|
+
=> true
|
74
|
+
>> u.name
|
75
|
+
=> "Stephen Richert"
|
76
|
+
>> u.version
|
77
|
+
=> 5
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('vestal_versions', '0.2.
|
5
|
+
Echoe.new('vestal_versions', '0.2.1') do |g|
|
6
6
|
g.description = %(Keep a DRY history of your ActiveRecord models' changes)
|
7
7
|
g.url = 'http://github.com/laserlemon/vestal_versions'
|
8
8
|
g.author = 'Steve Richert'
|
data/VERSION.yml
CHANGED
data/vestal_versions.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{vestal_versions}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Steve Richert"]
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vestal_versions", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{vestal_versions}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
19
19
|
s.summary = %q{Keep a DRY history of your ActiveRecord models' changes}
|
20
20
|
s.test_files = ["test/test_helper.rb", "test/vestal_versions_test.rb"]
|
21
21
|
|