laserlemon-vestal_versions 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -5
- data/VERSION +1 -1
- data/lib/vestal_versions.rb +10 -3
- data/vestal_versions.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Finally, DRY ActiveRecord versioning!
|
|
6
6
|
|
7
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
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
|
9
|
+
<tt>vestal_versions</tt>[http://github.com/laserlemon/vestal_versions] 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
10
|
|
11
11
|
And that's just what <tt>vestal_versions</tt> does. Not only can a model be reverted to a previous version number but also to a date or time!
|
12
12
|
|
@@ -15,13 +15,13 @@ And that's just what <tt>vestal_versions</tt> does. Not only can a model be reve
|
|
15
15
|
In <tt>environment.rb</tt>:
|
16
16
|
|
17
17
|
Rails::Initializer.run do |config|
|
18
|
-
config.gem '
|
18
|
+
config.gem 'vestal_versions'
|
19
19
|
end
|
20
20
|
|
21
21
|
At your application root, run:
|
22
22
|
|
23
23
|
$ sudo rake gems:install
|
24
|
-
|
24
|
+
|
25
25
|
Next, generate and run the first and last versioning migration you'll ever need:
|
26
26
|
|
27
27
|
$ script/generate vestal_versions_migration
|
@@ -33,9 +33,9 @@ To version an ActiveRecord model, simply add <tt>versioned</tt> to your class li
|
|
33
33
|
|
34
34
|
class User < ActiveRecord::Base
|
35
35
|
versioned
|
36
|
-
|
36
|
+
|
37
37
|
validates_presence_of :first_name, :last_name
|
38
|
-
|
38
|
+
|
39
39
|
def name
|
40
40
|
"#{first_name} #{last_name}"
|
41
41
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/vestal_versions.rb
CHANGED
@@ -7,7 +7,14 @@ module LaserLemon
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def versioned
|
10
|
+
def versioned(options = {})
|
11
|
+
class_inheritable_accessor :versioned_columns
|
12
|
+
self.versioned_columns = case
|
13
|
+
when options[:only] then column_names & Array(options[:only]).map(&:to_s)
|
14
|
+
when options[:except] then column_names - Array(options[:except]).map(&:to_s)
|
15
|
+
else column_names
|
16
|
+
end
|
17
|
+
|
11
18
|
has_many :versions, :as => :versioned, :order => 'versions.number ASC', :dependent => :delete_all do
|
12
19
|
def between(from, to)
|
13
20
|
from_number, to_number = number_at(from), number_at(to)
|
@@ -53,7 +60,7 @@ module LaserLemon
|
|
53
60
|
end
|
54
61
|
|
55
62
|
def needs_version?
|
56
|
-
!changed.empty?
|
63
|
+
!(versioned_columns & changed).empty?
|
57
64
|
end
|
58
65
|
|
59
66
|
def reset_version(new_version = nil)
|
@@ -66,7 +73,7 @@ module LaserLemon
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def create_version
|
69
|
-
versions.create(:changes => changes, :number => (last_version + 1))
|
76
|
+
versions.create(:changes => changes.slice(*versioned_columns), :number => (last_version + 1))
|
70
77
|
reset_version
|
71
78
|
end
|
72
79
|
|
data/vestal_versions.gemspec
CHANGED