rich-acts_as_revisable 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README
CHANGED
@@ -163,6 +163,10 @@ Then it can be installed as usual:
|
|
163
163
|
|
164
164
|
sudo gem install rich-acts_as_revisable
|
165
165
|
|
166
|
+
Once the gem is installed you'll want to activate it in your Rails app by adding the following line to config/environment.rb:
|
167
|
+
|
168
|
+
config.gem "rich-acts_as_revisable", :lib => "acts_as_revisable", :source => "http://gems.github.com"
|
169
|
+
|
166
170
|
== LICENSE:
|
167
171
|
|
168
172
|
(The MIT License)
|
@@ -32,10 +32,16 @@ module FatJam
|
|
32
32
|
def before_revisable_create
|
33
33
|
self[:revisable_is_current] = true
|
34
34
|
end
|
35
|
-
|
36
|
-
def before_revisable_update
|
37
|
-
return unless @aa_revisable_force_revision == true || (self.changed? && !(@aa_revisable_no_revision === true) && !(self.changed.map(&:downcase) & self.class.revisable_columns).blank?)
|
38
35
|
|
36
|
+
def should_revise?
|
37
|
+
return true if @aa_revisable_force_revision == true
|
38
|
+
return false if @aa_revisable_no_revision == true
|
39
|
+
return false unless self.changed?
|
40
|
+
!(self.changed.map(&:downcase) & self.class.revisable_columns).blank?
|
41
|
+
end
|
42
|
+
|
43
|
+
def before_revisable_update
|
44
|
+
return unless should_revise?
|
39
45
|
return false unless run_callbacks(:before_revise) { |r, o| r == false}
|
40
46
|
|
41
47
|
@revisable_revision = self.to_revision
|
@@ -88,7 +94,7 @@ module FatJam
|
|
88
94
|
end
|
89
95
|
|
90
96
|
options = args.extract_options!
|
91
|
-
|
97
|
+
|
92
98
|
rev = case args.first
|
93
99
|
when self.class.revision_class
|
94
100
|
args.first
|
@@ -101,19 +107,19 @@ module FatJam
|
|
101
107
|
when Time
|
102
108
|
revisions.find(:first, :conditions => ["? >= ? and ? <= ?", :revisable_revised_at, args.first, :revisable_current_at, args.first])
|
103
109
|
end
|
104
|
-
|
110
|
+
|
105
111
|
unless rev.run_callbacks(:before_restore) { |r, o| r == false}
|
106
112
|
raise ActiveRecord::RecordNotSaved
|
107
113
|
end
|
108
|
-
|
114
|
+
|
109
115
|
self.class.column_names.each do |col|
|
110
116
|
next unless self.class.revisable_should_clone_column? col
|
111
117
|
self[col] = rev[col]
|
112
118
|
end
|
113
|
-
|
119
|
+
|
114
120
|
@aa_revisable_no_revision = true if options.delete :without_revision
|
115
121
|
@aa_revisable_new_params = options
|
116
|
-
|
122
|
+
|
117
123
|
returning(@aa_revisable_no_revision ? save! : revise!) do
|
118
124
|
rev.run_callbacks(:after_restore)
|
119
125
|
run_callbacks(:after_revert)
|
@@ -129,9 +135,11 @@ module FatJam
|
|
129
135
|
def revise!
|
130
136
|
return if in_revision?
|
131
137
|
|
132
|
-
|
133
|
-
|
134
|
-
|
138
|
+
begin
|
139
|
+
@aa_revisable_force_revision = true
|
140
|
+
in_revision!
|
141
|
+
save!
|
142
|
+
ensure
|
135
143
|
in_revision!(false)
|
136
144
|
@aa_revisable_force_revision = false
|
137
145
|
end
|
@@ -151,7 +159,7 @@ module FatJam
|
|
151
159
|
aa_revisable_current_revisions[key] = val
|
152
160
|
aa_revisable_current_revisions.delete(key) unless val
|
153
161
|
end
|
154
|
-
|
162
|
+
|
155
163
|
def changeset(&block)
|
156
164
|
return unless block_given?
|
157
165
|
|
@@ -161,11 +169,14 @@ module FatJam
|
|
161
169
|
raise ActiveRecord::RecordNotSaved
|
162
170
|
end
|
163
171
|
|
164
|
-
|
172
|
+
begin
|
173
|
+
in_revision!
|
165
174
|
|
166
|
-
|
167
|
-
|
168
|
-
|
175
|
+
returning(yield(self)) do
|
176
|
+
run_callbacks(:after_changeset)
|
177
|
+
end
|
178
|
+
ensure
|
179
|
+
in_revision!(false)
|
169
180
|
end
|
170
181
|
end
|
171
182
|
|
@@ -177,7 +188,7 @@ module FatJam
|
|
177
188
|
|
178
189
|
module ClassMethods
|
179
190
|
def with_scope_with_revisable(*args, &block)
|
180
|
-
options = args.
|
191
|
+
options = (args.grep(Hash).first || {})[:find]
|
181
192
|
|
182
193
|
if options && options.delete(:with_revisions)
|
183
194
|
without_model_scope do
|
@@ -189,7 +200,7 @@ module FatJam
|
|
189
200
|
end
|
190
201
|
|
191
202
|
def find_with_revisable(*args)
|
192
|
-
options = args.
|
203
|
+
options = args.grep(Hash).first
|
193
204
|
|
194
205
|
if options && options.delete(:with_revisions)
|
195
206
|
without_model_scope do
|
@@ -201,9 +212,9 @@ module FatJam
|
|
201
212
|
end
|
202
213
|
|
203
214
|
def find_with_revisions(*args)
|
204
|
-
|
205
|
-
|
206
|
-
find_with_revisable(*
|
215
|
+
args << {} if args.grep(Hash).blank?
|
216
|
+
args.grep(Hash).first.update({:with_revisions => true})
|
217
|
+
find_with_revisable(*args)
|
207
218
|
end
|
208
219
|
|
209
220
|
def revision_class_name
|
@@ -10,7 +10,7 @@ module FatJam
|
|
10
10
|
set_table_name(revisable_class.table_name)
|
11
11
|
acts_as_scoped_model :find => {:conditions => {:revisable_is_current => false}}
|
12
12
|
|
13
|
-
CloneAssociations.
|
13
|
+
CloneAssociations.clone_associations(revisable_class, self)
|
14
14
|
|
15
15
|
define_callbacks :before_restore, :after_restore
|
16
16
|
|
@@ -2,15 +2,14 @@ module FatJam
|
|
2
2
|
module ActsAsRevisable
|
3
3
|
module CloneAssociations
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
return unless from.
|
7
|
-
|
8
|
-
|
5
|
+
def clone_associations(from, to)
|
6
|
+
return unless from.descends_from_active_record? && to.descends_from_active_record?
|
7
|
+
|
8
|
+
to.revision_cloned_associations.each do |key|
|
9
9
|
assoc = from.reflect_on_association(key)
|
10
10
|
meth = "clone_#{assoc.macro.to_s}_association"
|
11
11
|
meth = "clone_association" unless respond_to? meth
|
12
12
|
send(meth, assoc, to)
|
13
|
-
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|