modified_acts_as_versioned 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +82 -0
- data/MIT-LICENSE +20 -0
- data/README +28 -0
- data/RUNNING_UNIT_TESTS +41 -0
- data/Rakefile +50 -0
- data/VERSION.yml +4 -0
- data/acts_as_versioned.gemspec +29 -0
- data/init.rb +1 -0
- data/lib/acts_as_versioned.rb +488 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods/ClassMethods.html +336 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods.html +581 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned/ClassMethods.html +506 -0
- data/rdoc/classes/ActiveRecord/Acts/Versioned.html +187 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/CHANGELOG.html +288 -0
- data/rdoc/files/README.html +158 -0
- data/rdoc/files/RUNNING_UNIT_TESTS.html +158 -0
- data/rdoc/files/lib/acts_as_versioned_rb.html +129 -0
- data/rdoc/fr_class_index.html +30 -0
- data/rdoc/fr_file_index.html +30 -0
- data/rdoc/fr_method_index.html +54 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/test/abstract_unit.rb +60 -0
- data/test/database.yml +18 -0
- data/test/fixtures/authors.yml +6 -0
- data/test/fixtures/landmark.rb +3 -0
- data/test/fixtures/landmark_versions.yml +7 -0
- data/test/fixtures/landmarks.yml +7 -0
- data/test/fixtures/locked_pages.yml +10 -0
- data/test/fixtures/locked_pages_revisions.yml +27 -0
- data/test/fixtures/migrations/1_add_versioned_tables.rb +15 -0
- data/test/fixtures/page.rb +48 -0
- data/test/fixtures/page_versions.yml +16 -0
- data/test/fixtures/pages.yml +8 -0
- data/test/fixtures/widget.rb +6 -0
- data/test/migration_test.rb +47 -0
- data/test/schema.rb +82 -0
- data/test/versioned_test.rb +379 -0
- metadata +114 -0
@@ -0,0 +1,581 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: ActiveRecord::Acts::Versioned::ActMethods</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">ActiveRecord::Acts::Versioned::ActMethods</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../../files/lib/acts_as_versioned_rb.html">
|
59
|
+
lib/acts_as_versioned.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
<div id="method-list">
|
80
|
+
<h3 class="section-bar">Methods</h3>
|
81
|
+
|
82
|
+
<div class="name-list">
|
83
|
+
<a href="#M000007">altered?</a>
|
84
|
+
<a href="#M000002">clear_old_versions</a>
|
85
|
+
<a href="#M000008">clone_versioned_model</a>
|
86
|
+
<a href="#M000013">empty_callback</a>
|
87
|
+
<a href="#M000015">next_version</a>
|
88
|
+
<a href="#M000003">revert_to</a>
|
89
|
+
<a href="#M000004">revert_to!</a>
|
90
|
+
<a href="#M000001">save_version</a>
|
91
|
+
<a href="#M000009">save_version?</a>
|
92
|
+
<a href="#M000005">save_without_revision</a>
|
93
|
+
<a href="#M000006">save_without_revision!</a>
|
94
|
+
<a href="#M000014">set_new_version</a>
|
95
|
+
<a href="#M000010">version_condition_met?</a>
|
96
|
+
<a href="#M000012">without_locking</a>
|
97
|
+
<a href="#M000011">without_revision</a>
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
<!-- if includes -->
|
105
|
+
|
106
|
+
<div id="section">
|
107
|
+
|
108
|
+
<div id="class-list">
|
109
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
110
|
+
|
111
|
+
Module <a href="ActMethods/ClassMethods.html" class="link">ActiveRecord::Acts::Versioned::ActMethods::ClassMethods</a><br />
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<!-- if method_list -->
|
122
|
+
<div id="methods">
|
123
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
124
|
+
|
125
|
+
<div id="method-M000007" class="method-detail">
|
126
|
+
<a name="M000007"></a>
|
127
|
+
|
128
|
+
<div class="method-heading">
|
129
|
+
<a href="#M000007" class="method-signature">
|
130
|
+
<span class="method-name">altered?</span><span class="method-args">()</span>
|
131
|
+
</a>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
<div class="method-description">
|
135
|
+
<p><a class="source-toggle" href="#"
|
136
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
137
|
+
<div class="method-source-code" id="M000007-source">
|
138
|
+
<pre>
|
139
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 327</span>
|
140
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">altered?</span>
|
141
|
+
<span class="ruby-identifier">track_altered_attributes</span> <span class="ruby-value">? </span>(<span class="ruby-identifier">version_if_changed</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">changed</span>).<span class="ruby-identifier">length</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">version_if_changed</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">changed?</span>
|
142
|
+
<span class="ruby-keyword kw">end</span>
|
143
|
+
</pre>
|
144
|
+
</div>
|
145
|
+
</div>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<div id="method-M000002" class="method-detail">
|
149
|
+
<a name="M000002"></a>
|
150
|
+
|
151
|
+
<div class="method-heading">
|
152
|
+
<a href="#M000002" class="method-signature">
|
153
|
+
<span class="method-name">clear_old_versions</span><span class="method-args">()</span>
|
154
|
+
</a>
|
155
|
+
</div>
|
156
|
+
|
157
|
+
<div class="method-description">
|
158
|
+
<p>
|
159
|
+
Clears old revisions if a limit is set with the :limit option in
|
160
|
+
<tt>acts_as_versioned</tt>. Override this method to set your own criteria
|
161
|
+
for clearing old versions.
|
162
|
+
</p>
|
163
|
+
<p><a class="source-toggle" href="#"
|
164
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
165
|
+
<div class="method-source-code" id="M000002-source">
|
166
|
+
<pre>
|
167
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 285</span>
|
168
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_old_versions</span>
|
169
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">max_version_limit</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
170
|
+
<span class="ruby-identifier">excess_baggage</span> = <span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">version_column</span>).<span class="ruby-identifier">to_i</span> <span class="ruby-operator">-</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">max_version_limit</span>
|
171
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">excess_baggage</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
172
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">delete_all</span> [<span class="ruby-node">"#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?"</span>, <span class="ruby-identifier">excess_baggage</span>, <span class="ruby-identifier">id</span>]
|
173
|
+
<span class="ruby-keyword kw">end</span>
|
174
|
+
<span class="ruby-keyword kw">end</span>
|
175
|
+
</pre>
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
<div id="method-M000008" class="method-detail">
|
181
|
+
<a name="M000008"></a>
|
182
|
+
|
183
|
+
<div class="method-heading">
|
184
|
+
<a href="#M000008" class="method-signature">
|
185
|
+
<span class="method-name">clone_versioned_model</span><span class="method-args">(orig_model, new_model)</span>
|
186
|
+
</a>
|
187
|
+
</div>
|
188
|
+
|
189
|
+
<div class="method-description">
|
190
|
+
<p>
|
191
|
+
Clones a model. Used when saving a new version or reverting a model‘s
|
192
|
+
version.
|
193
|
+
</p>
|
194
|
+
<p><a class="source-toggle" href="#"
|
195
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
196
|
+
<div class="method-source-code" id="M000008-source">
|
197
|
+
<pre>
|
198
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 332</span>
|
199
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clone_versioned_model</span>(<span class="ruby-identifier">orig_model</span>, <span class="ruby-identifier">new_model</span>)
|
200
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_columns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
|
201
|
+
<span class="ruby-identifier">new_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{col.name}="</span>, <span class="ruby-identifier">orig_model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">orig_model</span>.<span class="ruby-identifier">has_attribute?</span>(<span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span>)
|
202
|
+
<span class="ruby-keyword kw">end</span>
|
203
|
+
|
204
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">orig_model</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_class</span>)
|
205
|
+
<span class="ruby-identifier">new_model</span>[<span class="ruby-identifier">new_model</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">inheritance_column</span>] = <span class="ruby-identifier">orig_model</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_inheritance_column</span>]
|
206
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">new_model</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_class</span>)
|
207
|
+
<span class="ruby-identifier">new_model</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_inheritance_column</span>] = <span class="ruby-identifier">orig_model</span>[<span class="ruby-identifier">orig_model</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">inheritance_column</span>]
|
208
|
+
<span class="ruby-keyword kw">end</span>
|
209
|
+
<span class="ruby-keyword kw">end</span>
|
210
|
+
</pre>
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
</div>
|
214
|
+
|
215
|
+
<div id="method-M000013" class="method-detail">
|
216
|
+
<a name="M000013"></a>
|
217
|
+
|
218
|
+
<div class="method-heading">
|
219
|
+
<a href="#M000013" class="method-signature">
|
220
|
+
<span class="method-name">empty_callback</span><span class="method-args">()</span>
|
221
|
+
</a>
|
222
|
+
</div>
|
223
|
+
|
224
|
+
<div class="method-description">
|
225
|
+
<p><a class="source-toggle" href="#"
|
226
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
227
|
+
<div class="method-source-code" id="M000013-source">
|
228
|
+
<pre>
|
229
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 382</span>
|
230
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty_callback</span>() <span class="ruby-keyword kw">end</span>
|
231
|
+
</pre>
|
232
|
+
</div>
|
233
|
+
</div>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<div id="method-M000003" class="method-detail">
|
237
|
+
<a name="M000003"></a>
|
238
|
+
|
239
|
+
<div class="method-heading">
|
240
|
+
<a href="#M000003" class="method-signature">
|
241
|
+
<span class="method-name">revert_to</span><span class="method-args">(version)</span>
|
242
|
+
</a>
|
243
|
+
</div>
|
244
|
+
|
245
|
+
<div class="method-description">
|
246
|
+
<p>
|
247
|
+
Reverts a model to a given version. Takes either a version number or an
|
248
|
+
instance of the versioned model
|
249
|
+
</p>
|
250
|
+
<p><a class="source-toggle" href="#"
|
251
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
252
|
+
<div class="method-source-code" id="M000003-source">
|
253
|
+
<pre>
|
254
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 294</span>
|
255
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">revert_to</span>(<span class="ruby-identifier">version</span>)
|
256
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_class</span>)
|
257
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_foreign_key</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span> <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">version</span>.<span class="ruby-identifier">new_record?</span>
|
258
|
+
<span class="ruby-keyword kw">else</span>
|
259
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">version</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versions_name</span>).<span class="ruby-identifier">send</span>(<span class="ruby-node">"find_by_#{self.class.version_column}"</span>, <span class="ruby-identifier">version</span>)
|
260
|
+
<span class="ruby-keyword kw">end</span>
|
261
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clone_versioned_model</span>(<span class="ruby-identifier">version</span>, <span class="ruby-keyword kw">self</span>)
|
262
|
+
<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{self.class.version_column}="</span>, <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">version_column</span>))
|
263
|
+
<span class="ruby-keyword kw">true</span>
|
264
|
+
<span class="ruby-keyword kw">end</span>
|
265
|
+
</pre>
|
266
|
+
</div>
|
267
|
+
</div>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
<div id="method-M000004" class="method-detail">
|
271
|
+
<a name="M000004"></a>
|
272
|
+
|
273
|
+
<div class="method-heading">
|
274
|
+
<a href="#M000004" class="method-signature">
|
275
|
+
<span class="method-name">revert_to!</span><span class="method-args">(version)</span>
|
276
|
+
</a>
|
277
|
+
</div>
|
278
|
+
|
279
|
+
<div class="method-description">
|
280
|
+
<p>
|
281
|
+
Reverts a model to a given version and saves the model. Takes either a
|
282
|
+
version number or an instance of the versioned model
|
283
|
+
</p>
|
284
|
+
<p><a class="source-toggle" href="#"
|
285
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
286
|
+
<div class="method-source-code" id="M000004-source">
|
287
|
+
<pre>
|
288
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 307</span>
|
289
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">revert_to!</span>(<span class="ruby-identifier">version</span>)
|
290
|
+
<span class="ruby-identifier">revert_to</span>(<span class="ruby-identifier">version</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">save_without_revision</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
|
291
|
+
<span class="ruby-keyword kw">end</span>
|
292
|
+
</pre>
|
293
|
+
</div>
|
294
|
+
</div>
|
295
|
+
</div>
|
296
|
+
|
297
|
+
<div id="method-M000001" class="method-detail">
|
298
|
+
<a name="M000001"></a>
|
299
|
+
|
300
|
+
<div class="method-heading">
|
301
|
+
<a href="#M000001" class="method-signature">
|
302
|
+
<span class="method-name">save_version</span><span class="method-args">()</span>
|
303
|
+
</a>
|
304
|
+
</div>
|
305
|
+
|
306
|
+
<div class="method-description">
|
307
|
+
<p>
|
308
|
+
Saves a version of the model in the versioned table. This is called in the
|
309
|
+
after_save callback by default
|
310
|
+
</p>
|
311
|
+
<p><a class="source-toggle" href="#"
|
312
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
313
|
+
<div class="method-source-code" id="M000001-source">
|
314
|
+
<pre>
|
315
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 272</span>
|
316
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_version</span>
|
317
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@saving_version</span>
|
318
|
+
<span class="ruby-ivar">@saving_version</span> = <span class="ruby-keyword kw">nil</span>
|
319
|
+
<span class="ruby-identifier">rev</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">new</span>
|
320
|
+
<span class="ruby-identifier">clone_versioned_model</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">rev</span>)
|
321
|
+
<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{self.class.version_column}="</span>, <span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">version_column</span>))
|
322
|
+
<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{self.class.versioned_foreign_key}="</span>, <span class="ruby-identifier">id</span>)
|
323
|
+
<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">save</span>
|
324
|
+
<span class="ruby-keyword kw">end</span>
|
325
|
+
<span class="ruby-keyword kw">end</span>
|
326
|
+
</pre>
|
327
|
+
</div>
|
328
|
+
</div>
|
329
|
+
</div>
|
330
|
+
|
331
|
+
<div id="method-M000009" class="method-detail">
|
332
|
+
<a name="M000009"></a>
|
333
|
+
|
334
|
+
<div class="method-heading">
|
335
|
+
<a href="#M000009" class="method-signature">
|
336
|
+
<span class="method-name">save_version?</span><span class="method-args">()</span>
|
337
|
+
</a>
|
338
|
+
</div>
|
339
|
+
|
340
|
+
<div class="method-description">
|
341
|
+
<p>
|
342
|
+
Checks whether a new version shall be saved or not. Calls <tt><a
|
343
|
+
href="ActMethods.html#M000010">version_condition_met?</a></tt> and
|
344
|
+
<tt>changed?</tt>.
|
345
|
+
</p>
|
346
|
+
<p><a class="source-toggle" href="#"
|
347
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
348
|
+
<div class="method-source-code" id="M000009-source">
|
349
|
+
<pre>
|
350
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 345</span>
|
351
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_version?</span>
|
352
|
+
<span class="ruby-identifier">version_condition_met?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">altered?</span>
|
353
|
+
<span class="ruby-keyword kw">end</span>
|
354
|
+
</pre>
|
355
|
+
</div>
|
356
|
+
</div>
|
357
|
+
</div>
|
358
|
+
|
359
|
+
<div id="method-M000005" class="method-detail">
|
360
|
+
<a name="M000005"></a>
|
361
|
+
|
362
|
+
<div class="method-heading">
|
363
|
+
<a href="#M000005" class="method-signature">
|
364
|
+
<span class="method-name">save_without_revision</span><span class="method-args">()</span>
|
365
|
+
</a>
|
366
|
+
</div>
|
367
|
+
|
368
|
+
<div class="method-description">
|
369
|
+
<p>
|
370
|
+
Temporarily turns off Optimistic Locking while saving. Used when reverting
|
371
|
+
so that a new version is not created.
|
372
|
+
</p>
|
373
|
+
<p><a class="source-toggle" href="#"
|
374
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
375
|
+
<div class="method-source-code" id="M000005-source">
|
376
|
+
<pre>
|
377
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 312</span>
|
378
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_without_revision</span>
|
379
|
+
<span class="ruby-identifier">save_without_revision!</span>
|
380
|
+
<span class="ruby-keyword kw">true</span>
|
381
|
+
<span class="ruby-keyword kw">rescue</span>
|
382
|
+
<span class="ruby-keyword kw">false</span>
|
383
|
+
<span class="ruby-keyword kw">end</span>
|
384
|
+
</pre>
|
385
|
+
</div>
|
386
|
+
</div>
|
387
|
+
</div>
|
388
|
+
|
389
|
+
<div id="method-M000006" class="method-detail">
|
390
|
+
<a name="M000006"></a>
|
391
|
+
|
392
|
+
<div class="method-heading">
|
393
|
+
<a href="#M000006" class="method-signature">
|
394
|
+
<span class="method-name">save_without_revision!</span><span class="method-args">()</span>
|
395
|
+
</a>
|
396
|
+
</div>
|
397
|
+
|
398
|
+
<div class="method-description">
|
399
|
+
<p><a class="source-toggle" href="#"
|
400
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
401
|
+
<div class="method-source-code" id="M000006-source">
|
402
|
+
<pre>
|
403
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 319</span>
|
404
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_without_revision!</span>
|
405
|
+
<span class="ruby-identifier">without_locking</span> <span class="ruby-keyword kw">do</span>
|
406
|
+
<span class="ruby-identifier">without_revision</span> <span class="ruby-keyword kw">do</span>
|
407
|
+
<span class="ruby-identifier">save!</span>
|
408
|
+
<span class="ruby-keyword kw">end</span>
|
409
|
+
<span class="ruby-keyword kw">end</span>
|
410
|
+
<span class="ruby-keyword kw">end</span>
|
411
|
+
</pre>
|
412
|
+
</div>
|
413
|
+
</div>
|
414
|
+
</div>
|
415
|
+
|
416
|
+
<div id="method-M000010" class="method-detail">
|
417
|
+
<a name="M000010"></a>
|
418
|
+
|
419
|
+
<div class="method-heading">
|
420
|
+
<a href="#M000010" class="method-signature">
|
421
|
+
<span class="method-name">version_condition_met?</span><span class="method-args">()</span>
|
422
|
+
</a>
|
423
|
+
</div>
|
424
|
+
|
425
|
+
<div class="method-description">
|
426
|
+
<p>
|
427
|
+
Checks condition set in the :if option to check whether a revision should
|
428
|
+
be created or not. Override this for custom version condition checking.
|
429
|
+
</p>
|
430
|
+
<p><a class="source-toggle" href="#"
|
431
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
432
|
+
<div class="method-source-code" id="M000010-source">
|
433
|
+
<pre>
|
434
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 351</span>
|
435
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">version_condition_met?</span>
|
436
|
+
<span class="ruby-keyword kw">case</span>
|
437
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">version_condition</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
|
438
|
+
<span class="ruby-identifier">send</span>(<span class="ruby-identifier">version_condition</span>)
|
439
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">version_condition</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:call</span>) <span class="ruby-operator">&&</span> (<span class="ruby-identifier">version_condition</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version_condition</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">==</span> <span class="ruby-value">-1</span>)
|
440
|
+
<span class="ruby-identifier">version_condition</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>)
|
441
|
+
<span class="ruby-keyword kw">else</span>
|
442
|
+
<span class="ruby-identifier">version_condition</span>
|
443
|
+
<span class="ruby-keyword kw">end</span>
|
444
|
+
<span class="ruby-keyword kw">end</span>
|
445
|
+
</pre>
|
446
|
+
</div>
|
447
|
+
</div>
|
448
|
+
</div>
|
449
|
+
|
450
|
+
<div id="method-M000012" class="method-detail">
|
451
|
+
<a name="M000012"></a>
|
452
|
+
|
453
|
+
<div class="method-heading">
|
454
|
+
<a href="#M000012" class="method-signature">
|
455
|
+
<span class="method-name">without_locking</span><span class="method-args">(&block)</span>
|
456
|
+
</a>
|
457
|
+
</div>
|
458
|
+
|
459
|
+
<div class="method-description">
|
460
|
+
<p>
|
461
|
+
Turns off optimistic locking for the duration of the block
|
462
|
+
</p>
|
463
|
+
<pre>
|
464
|
+
@foo.without_locking do
|
465
|
+
@foo.save
|
466
|
+
end
|
467
|
+
</pre>
|
468
|
+
<p><a class="source-toggle" href="#"
|
469
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
470
|
+
<div class="method-source-code" id="M000012-source">
|
471
|
+
<pre>
|
472
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 378</span>
|
473
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_locking</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
474
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">without_locking</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
475
|
+
<span class="ruby-keyword kw">end</span>
|
476
|
+
</pre>
|
477
|
+
</div>
|
478
|
+
</div>
|
479
|
+
</div>
|
480
|
+
|
481
|
+
<div id="method-M000011" class="method-detail">
|
482
|
+
<a name="M000011"></a>
|
483
|
+
|
484
|
+
<div class="method-heading">
|
485
|
+
<a href="#M000011" class="method-signature">
|
486
|
+
<span class="method-name">without_revision</span><span class="method-args">(&block)</span>
|
487
|
+
</a>
|
488
|
+
</div>
|
489
|
+
|
490
|
+
<div class="method-description">
|
491
|
+
<p>
|
492
|
+
Executes the block with the versioning callbacks disabled.
|
493
|
+
</p>
|
494
|
+
<pre>
|
495
|
+
@foo.without_revision do
|
496
|
+
@foo.save
|
497
|
+
end
|
498
|
+
</pre>
|
499
|
+
<p><a class="source-toggle" href="#"
|
500
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
501
|
+
<div class="method-source-code" id="M000011-source">
|
502
|
+
<pre>
|
503
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 368</span>
|
504
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_revision</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
505
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">without_revision</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
506
|
+
<span class="ruby-keyword kw">end</span>
|
507
|
+
</pre>
|
508
|
+
</div>
|
509
|
+
</div>
|
510
|
+
</div>
|
511
|
+
|
512
|
+
<h3 class="section-bar">Protected Instance methods</h3>
|
513
|
+
|
514
|
+
<div id="method-M000015" class="method-detail">
|
515
|
+
<a name="M000015"></a>
|
516
|
+
|
517
|
+
<div class="method-heading">
|
518
|
+
<a href="#M000015" class="method-signature">
|
519
|
+
<span class="method-name">next_version</span><span class="method-args">()</span>
|
520
|
+
</a>
|
521
|
+
</div>
|
522
|
+
|
523
|
+
<div class="method-description">
|
524
|
+
<p>
|
525
|
+
Gets the next available version for the current record, or 1 for a new
|
526
|
+
record
|
527
|
+
</p>
|
528
|
+
<p><a class="source-toggle" href="#"
|
529
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
530
|
+
<div class="method-source-code" id="M000015-source">
|
531
|
+
<pre>
|
532
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 392</span>
|
533
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">next_version</span>
|
534
|
+
(<span class="ruby-identifier">new_record?</span> <span class="ruby-value">? </span><span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versions_name</span>).<span class="ruby-identifier">calculate</span>(<span class="ruby-identifier">:max</span>, <span class="ruby-identifier">version_column</span>).<span class="ruby-identifier">to_i</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
535
|
+
<span class="ruby-keyword kw">end</span>
|
536
|
+
</pre>
|
537
|
+
</div>
|
538
|
+
</div>
|
539
|
+
</div>
|
540
|
+
|
541
|
+
<div id="method-M000014" class="method-detail">
|
542
|
+
<a name="M000014"></a>
|
543
|
+
|
544
|
+
<div class="method-heading">
|
545
|
+
<a href="#M000014" class="method-signature">
|
546
|
+
<span class="method-name">set_new_version</span><span class="method-args">()</span>
|
547
|
+
</a>
|
548
|
+
</div>
|
549
|
+
|
550
|
+
<div class="method-description">
|
551
|
+
<p>
|
552
|
+
sets the new version before saving, unless you‘re using optimistic
|
553
|
+
locking. In that case, let it take care of the version.
|
554
|
+
</p>
|
555
|
+
<p><a class="source-toggle" href="#"
|
556
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
557
|
+
<div class="method-source-code" id="M000014-source">
|
558
|
+
<pre>
|
559
|
+
<span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 386</span>
|
560
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_new_version</span>
|
561
|
+
<span class="ruby-ivar">@saving_version</span> = <span class="ruby-identifier">new_record?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">save_version?</span>
|
562
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{self.class.version_column}="</span>, <span class="ruby-identifier">next_version</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_record?</span> <span class="ruby-operator">||</span> (<span class="ruby-operator">!</span><span class="ruby-identifier">locking_enabled?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">save_version?</span>)
|
563
|
+
<span class="ruby-keyword kw">end</span>
|
564
|
+
</pre>
|
565
|
+
</div>
|
566
|
+
</div>
|
567
|
+
</div>
|
568
|
+
|
569
|
+
|
570
|
+
</div>
|
571
|
+
|
572
|
+
|
573
|
+
</div>
|
574
|
+
|
575
|
+
|
576
|
+
<div id="validator-badges">
|
577
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
578
|
+
</div>
|
579
|
+
|
580
|
+
</body>
|
581
|
+
</html>
|