modified_acts_as_versioned 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG +82 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +28 -0
  5. data/RUNNING_UNIT_TESTS +41 -0
  6. data/Rakefile +50 -0
  7. data/VERSION.yml +4 -0
  8. data/acts_as_versioned.gemspec +29 -0
  9. data/init.rb +1 -0
  10. data/lib/acts_as_versioned.rb +488 -0
  11. data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods/ClassMethods.html +336 -0
  12. data/rdoc/classes/ActiveRecord/Acts/Versioned/ActMethods.html +581 -0
  13. data/rdoc/classes/ActiveRecord/Acts/Versioned/ClassMethods.html +506 -0
  14. data/rdoc/classes/ActiveRecord/Acts/Versioned.html +187 -0
  15. data/rdoc/created.rid +1 -0
  16. data/rdoc/files/CHANGELOG.html +288 -0
  17. data/rdoc/files/README.html +158 -0
  18. data/rdoc/files/RUNNING_UNIT_TESTS.html +158 -0
  19. data/rdoc/files/lib/acts_as_versioned_rb.html +129 -0
  20. data/rdoc/fr_class_index.html +30 -0
  21. data/rdoc/fr_file_index.html +30 -0
  22. data/rdoc/fr_method_index.html +54 -0
  23. data/rdoc/index.html +24 -0
  24. data/rdoc/rdoc-style.css +208 -0
  25. data/test/abstract_unit.rb +60 -0
  26. data/test/database.yml +18 -0
  27. data/test/fixtures/authors.yml +6 -0
  28. data/test/fixtures/landmark.rb +3 -0
  29. data/test/fixtures/landmark_versions.yml +7 -0
  30. data/test/fixtures/landmarks.yml +7 -0
  31. data/test/fixtures/locked_pages.yml +10 -0
  32. data/test/fixtures/locked_pages_revisions.yml +27 -0
  33. data/test/fixtures/migrations/1_add_versioned_tables.rb +15 -0
  34. data/test/fixtures/page.rb +48 -0
  35. data/test/fixtures/page_versions.yml +16 -0
  36. data/test/fixtures/pages.yml +8 -0
  37. data/test/fixtures/widget.rb +6 -0
  38. data/test/migration_test.rb +47 -0
  39. data/test/schema.rb +82 -0
  40. data/test/versioned_test.rb +379 -0
  41. metadata +114 -0
@@ -0,0 +1,506 @@
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::ClassMethods</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::ClassMethods</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="#M000022">acts_as_versioned</a>&nbsp;&nbsp;
84
+ <a href="#M000025">after</a>&nbsp;&nbsp;
85
+ <a href="#M000024">before</a>&nbsp;&nbsp;
86
+ <a href="#M000027">next</a>&nbsp;&nbsp;
87
+ <a href="#M000026">previous</a>&nbsp;&nbsp;
88
+ <a href="#M000023">reloadable?</a>&nbsp;&nbsp;
89
+ <a href="#M000028">versions_count</a>&nbsp;&nbsp;
90
+ </div>
91
+ </div>
92
+
93
+ </div>
94
+
95
+
96
+ <!-- if includes -->
97
+
98
+ <div id="section">
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ <!-- if method_list -->
108
+ <div id="methods">
109
+ <h3 class="section-bar">Public Class methods</h3>
110
+
111
+ <div id="method-M000025" class="method-detail">
112
+ <a name="M000025"></a>
113
+
114
+ <div class="method-heading">
115
+ <a href="#M000025" class="method-signature">
116
+ <span class="method-name">after</span><span class="method-args">(version)</span>
117
+ </a>
118
+ </div>
119
+
120
+ <div class="method-description">
121
+ <p>
122
+ find first version <a href="ClassMethods.html#M000025">after</a> the given
123
+ version.
124
+ </p>
125
+ <p><a class="source-toggle" href="#"
126
+ onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
127
+ <div class="method-source-code" id="M000025-source">
128
+ <pre>
129
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 237</span>
130
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">after</span>(<span class="ruby-identifier">version</span>)
131
+ <span class="ruby-identifier">find</span> <span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'version'</span>,
132
+ <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{original_class.versioned_foreign_key} = ? and version &gt; ?&quot;</span>, <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">original_class</span>.<span class="ruby-identifier">versioned_foreign_key</span>), <span class="ruby-identifier">version</span>.<span class="ruby-identifier">version</span>]
133
+ <span class="ruby-keyword kw">end</span>
134
+ </pre>
135
+ </div>
136
+ </div>
137
+ </div>
138
+
139
+ <div id="method-M000024" class="method-detail">
140
+ <a name="M000024"></a>
141
+
142
+ <div class="method-heading">
143
+ <a href="#M000024" class="method-signature">
144
+ <span class="method-name">before</span><span class="method-args">(version)</span>
145
+ </a>
146
+ </div>
147
+
148
+ <div class="method-description">
149
+ <p>
150
+ find first version <a href="ClassMethods.html#M000024">before</a> the given
151
+ version
152
+ </p>
153
+ <p><a class="source-toggle" href="#"
154
+ onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
155
+ <div class="method-source-code" id="M000024-source">
156
+ <pre>
157
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 231</span>
158
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">before</span>(<span class="ruby-identifier">version</span>)
159
+ <span class="ruby-identifier">find</span> <span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'version desc'</span>,
160
+ <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{original_class.versioned_foreign_key} = ? and version &lt; ?&quot;</span>, <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">original_class</span>.<span class="ruby-identifier">versioned_foreign_key</span>), <span class="ruby-identifier">version</span>.<span class="ruby-identifier">version</span>]
161
+ <span class="ruby-keyword kw">end</span>
162
+ </pre>
163
+ </div>
164
+ </div>
165
+ </div>
166
+
167
+ <div id="method-M000023" class="method-detail">
168
+ <a name="M000023"></a>
169
+
170
+ <div class="method-heading">
171
+ <a href="#M000023" class="method-signature">
172
+ <span class="method-name">reloadable?</span><span class="method-args">()</span>
173
+ </a>
174
+ </div>
175
+
176
+ <div class="method-description">
177
+ <p><a class="source-toggle" href="#"
178
+ onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
179
+ <div class="method-source-code" id="M000023-source">
180
+ <pre>
181
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 229</span>
182
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reloadable?</span> ; <span class="ruby-keyword kw">false</span> ; <span class="ruby-keyword kw">end</span>
183
+ </pre>
184
+ </div>
185
+ </div>
186
+ </div>
187
+
188
+ <h3 class="section-bar">Public Instance methods</h3>
189
+
190
+ <div id="method-M000022" class="method-detail">
191
+ <a name="M000022"></a>
192
+
193
+ <div class="method-heading">
194
+ <a href="#M000022" class="method-signature">
195
+ <span class="method-name">acts_as_versioned</span><span class="method-args">(options = {}, &amp;extension)</span>
196
+ </a>
197
+ </div>
198
+
199
+ <div class="method-description">
200
+ <h2>Configuration options</h2>
201
+ <ul>
202
+ <li><tt>class_name</tt> - versioned model class name (default: PageVersion in
203
+ the above example)
204
+
205
+ </li>
206
+ <li><tt>table_name</tt> - versioned model table name (default: page_versions in
207
+ the above example)
208
+
209
+ </li>
210
+ <li><tt>foreign_key</tt> - foreign key used to relate the versioned model to
211
+ the original model (default: page_id in the above example)
212
+
213
+ </li>
214
+ <li><tt>inheritance_column</tt> - name of the column to save the model&#8216;s
215
+ inheritance_column value for STI. (default: versioned_type)
216
+
217
+ </li>
218
+ <li><tt>version_column</tt> - name of the column in the model that keeps the
219
+ version number (default: version)
220
+
221
+ </li>
222
+ <li><tt>sequence_name</tt> - name of the custom sequence to be used by the
223
+ versioned model.
224
+
225
+ </li>
226
+ <li><tt>limit</tt> - number of revisions to keep, defaults to unlimited
227
+
228
+ </li>
229
+ <li><tt>versions_name</tt> - name to be used to access the versions.. DH
230
+
231
+ </li>
232
+ <li><tt>if</tt> - symbol of method to check <a
233
+ href="ClassMethods.html#M000024">before</a> saving a new version. If this
234
+ method returns false, a new version is not saved. For finer control, pass
235
+ either a Proc or modify Model#version_condition_met?
236
+
237
+ <pre>
238
+ acts_as_versioned :if =&gt; Proc.new { |auction| !auction.expired? }
239
+ </pre>
240
+ <p>
241
+ or&#8230;
242
+ </p>
243
+ <pre>
244
+ class Auction
245
+ def version_condition_met? # totally bypasses the &lt;tt&gt;:if&lt;/tt&gt; option
246
+ !expired?
247
+ end
248
+ end
249
+ </pre>
250
+ </li>
251
+ <li><tt>if_changed</tt> - Simple way of specifying attributes that are required
252
+ to be changed <a href="ClassMethods.html#M000024">before</a> saving a
253
+ model. This takes either a symbol or array of symbols.
254
+
255
+ </li>
256
+ <li><tt>extend</tt> - Lets you specify a module to be mixed in both the
257
+ original and versioned models. You can also just pass a block to create an
258
+ anonymous mixin:
259
+
260
+ <pre>
261
+ class Auction
262
+ acts_as_versioned do
263
+ def started?
264
+ !started_at.nil?
265
+ end
266
+ end
267
+ end
268
+ </pre>
269
+ <p>
270
+ or&#8230;
271
+ </p>
272
+ <pre>
273
+ module AuctionExtension
274
+ def started?
275
+ !started_at.nil?
276
+ end
277
+ end
278
+ class Auction
279
+ acts_as_versioned :extend =&gt; AuctionExtension
280
+ end
281
+
282
+ Example code:
283
+
284
+ @auction = Auction.find(1)
285
+ @auction.started?
286
+ @auction.versions.first.started?
287
+ </pre>
288
+ </li>
289
+ </ul>
290
+ <h2>Database Schema</h2>
291
+ <p>
292
+ The model that you&#8216;re versioning needs to have a
293
+ &#8216;version&#8217; attribute. The model is versioned into a table called
294
+ #{model}_versions where the model name is singlular. The _versions table
295
+ should contain all the fields you want versioned, the same version column,
296
+ and a #{model}_id foreign key field.
297
+ </p>
298
+ <p>
299
+ A lock_version field is also accepted if your model uses Optimistic
300
+ Locking. If your table uses Single Table inheritance, then that field is
301
+ reflected in the versioned model as &#8216;versioned_type&#8217; by
302
+ default.
303
+ </p>
304
+ <p>
305
+ Acts_as_versioned comes prepared with the
306
+ ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table
307
+ method, perfect for a migration. It will also create the version column if
308
+ the main model does not already have it.
309
+ </p>
310
+ <pre>
311
+ class AddVersions &lt; ActiveRecord::Migration
312
+ def self.up
313
+ # create_versioned_table takes the same options hash
314
+ # that create_table does
315
+ Post.create_versioned_table
316
+ end
317
+
318
+ def self.down
319
+ Post.drop_versioned_table
320
+ end
321
+ end
322
+ </pre>
323
+ <h2>Changing What Fields Are <a href="../Versioned.html">Versioned</a></h2>
324
+ <p>
325
+ By default, <a href="ClassMethods.html#M000022">acts_as_versioned</a> will
326
+ version all but these fields:
327
+ </p>
328
+ <pre>
329
+ [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
330
+ </pre>
331
+ <p>
332
+ You can add or change those by modifying non_versioned_columns. Note that
333
+ this takes strings and not symbols.
334
+ </p>
335
+ <pre>
336
+ class Post &lt; ActiveRecord::Base
337
+ acts_as_versioned
338
+ self.non_versioned_columns &lt;&lt; 'comments_count'
339
+ end
340
+ </pre>
341
+ <p><a class="source-toggle" href="#"
342
+ onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
343
+ <div class="method-source-code" id="M000022-source">
344
+ <pre>
345
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 166</span>
346
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">acts_as_versioned</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">extension</span>)
347
+ <span class="ruby-comment cmt"># don't allow multiple calls</span>
348
+ <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">included_modules</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Versioned</span><span class="ruby-operator">::</span><span class="ruby-constant">ActMethods</span>)
349
+
350
+ <span class="ruby-identifier">send</span> <span class="ruby-identifier">:include</span>, <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Versioned</span><span class="ruby-operator">::</span><span class="ruby-constant">ActMethods</span>
351
+
352
+ <span class="ruby-identifier">cattr_accessor</span> <span class="ruby-identifier">:versioned_class_name</span>, <span class="ruby-identifier">:versioned_foreign_key</span>, <span class="ruby-identifier">:versioned_table_name</span>, <span class="ruby-identifier">:versioned_inheritance_column</span>,
353
+ <span class="ruby-identifier">:version_column</span>, <span class="ruby-identifier">:max_version_limit</span>, <span class="ruby-identifier">:track_altered_attributes</span>, <span class="ruby-identifier">:version_condition</span>, <span class="ruby-identifier">:version_sequence_name</span>, <span class="ruby-identifier">:non_versioned_columns</span>,
354
+ <span class="ruby-identifier">:version_association_options</span>, <span class="ruby-identifier">:version_if_changed</span>, <span class="ruby-identifier">:versions_name</span>
355
+
356
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versioned_class_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:class_name</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;Version&quot;</span>
357
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versioned_foreign_key</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:foreign_key</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">foreign_key</span>
358
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versioned_table_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:table_name</span>] <span class="ruby-operator">||</span> <span class="ruby-node">&quot;#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}&quot;</span>
359
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versioned_inheritance_column</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:inheritance_column</span>] <span class="ruby-operator">||</span> <span class="ruby-node">&quot;versioned_#{inheritance_column}&quot;</span>
360
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version_column</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:version_column</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'version'</span>
361
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version_sequence_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sequence_name</span>]
362
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">max_version_limit</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:limit</span>].<span class="ruby-identifier">to_i</span>
363
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version_condition</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">true</span>
364
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">versions_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:versions_name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:versions</span>
365
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">non_versioned_columns</span> = [<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">primary_key</span>, <span class="ruby-identifier">inheritance_column</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version_column</span>, <span class="ruby-value str">'lock_version'</span>, <span class="ruby-identifier">versioned_inheritance_column</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:non_versioned_columns</span>].<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:to_s</span>)
366
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version_association_options</span> = {
367
+ <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{self.to_s}::#{versioned_class_name}&quot;</span>,
368
+ <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">versioned_foreign_key</span>,
369
+ <span class="ruby-identifier">:dependent</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:delete_all</span>
370
+ }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:association_options</span>] <span class="ruby-operator">||</span> {})
371
+
372
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
373
+ <span class="ruby-identifier">extension_module_name</span> = <span class="ruby-node">&quot;#{versioned_class_name}Extension&quot;</span>
374
+ <span class="ruby-identifier">silence_warnings</span> <span class="ruby-keyword kw">do</span>
375
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">const_set</span>(<span class="ruby-identifier">extension_module_name</span>, <span class="ruby-constant">Module</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">extension</span>))
376
+ <span class="ruby-keyword kw">end</span>
377
+
378
+ <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:extend</span>] = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">extension_module_name</span>)
379
+ <span class="ruby-keyword kw">end</span>
380
+
381
+ <span class="ruby-identifier">class_eval</span> <span class="ruby-value str">&quot;has_many :\#{versions_name.to_s}, version_association_options do\n# finds earliest version of this record\ndef earliest\n@earliest ||= find(:first, :order =&gt; '\#{version_column}')\nend\n\n# find latest version of this record\ndef latest\n@latest ||= find(:first, :order =&gt; '\#{version_column} desc')\nend\nend\nbefore_save :set_new_version\nafter_save :save_version\nafter_save :clear_old_versions\n\nunless options[:if_changed].nil?\nself.track_altered_attributes = true\noptions[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array)\nself.version_if_changed = options[:if_changed].map(&amp;:to_s)\nend\n\ninclude options[:extend] if options[:extend].is_a?(Module)\n&quot;</span>
382
+
383
+ <span class="ruby-comment cmt"># create the dynamic versioned model</span>
384
+ <span class="ruby-identifier">const_set</span>(<span class="ruby-identifier">versioned_class_name</span>, <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>)).<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
385
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reloadable?</span> ; <span class="ruby-keyword kw">false</span> ; <span class="ruby-keyword kw">end</span>
386
+ <span class="ruby-comment cmt"># find first version before the given version</span>
387
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">before</span>(<span class="ruby-identifier">version</span>)
388
+ <span class="ruby-identifier">find</span> <span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'version desc'</span>,
389
+ <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{original_class.versioned_foreign_key} = ? and version &lt; ?&quot;</span>, <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">original_class</span>.<span class="ruby-identifier">versioned_foreign_key</span>), <span class="ruby-identifier">version</span>.<span class="ruby-identifier">version</span>]
390
+ <span class="ruby-keyword kw">end</span>
391
+
392
+ <span class="ruby-comment cmt"># find first version after the given version.</span>
393
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">after</span>(<span class="ruby-identifier">version</span>)
394
+ <span class="ruby-identifier">find</span> <span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'version'</span>,
395
+ <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-node">&quot;#{original_class.versioned_foreign_key} = ? and version &gt; ?&quot;</span>, <span class="ruby-identifier">version</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">original_class</span>.<span class="ruby-identifier">versioned_foreign_key</span>), <span class="ruby-identifier">version</span>.<span class="ruby-identifier">version</span>]
396
+ <span class="ruby-keyword kw">end</span>
397
+
398
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous</span>
399
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">before</span>(<span class="ruby-keyword kw">self</span>)
400
+ <span class="ruby-keyword kw">end</span>
401
+
402
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
403
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">after</span>(<span class="ruby-keyword kw">self</span>)
404
+ <span class="ruby-keyword kw">end</span>
405
+
406
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versions_count</span>
407
+ <span class="ruby-identifier">page</span>.<span class="ruby-identifier">version</span>
408
+ <span class="ruby-keyword kw">end</span>
409
+ <span class="ruby-keyword kw">end</span>
410
+
411
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">cattr_accessor</span> <span class="ruby-identifier">:original_class</span>
412
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">original_class</span> = <span class="ruby-keyword kw">self</span>
413
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">set_table_name</span> <span class="ruby-identifier">versioned_table_name</span>
414
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">belongs_to</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">demodulize</span>.<span class="ruby-identifier">underscore</span>.<span class="ruby-identifier">to_sym</span>,
415
+ <span class="ruby-identifier">:class_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;::#{self.to_s}&quot;</span>,
416
+ <span class="ruby-identifier">:foreign_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">versioned_foreign_key</span>
417
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">:include</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:extend</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:extend</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Module</span>)
418
+ <span class="ruby-identifier">versioned_class</span>.<span class="ruby-identifier">set_sequence_name</span> <span class="ruby-identifier">version_sequence_name</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">version_sequence_name</span>
419
+ <span class="ruby-keyword kw">end</span>
420
+ </pre>
421
+ </div>
422
+ </div>
423
+ </div>
424
+
425
+ <div id="method-M000027" class="method-detail">
426
+ <a name="M000027"></a>
427
+
428
+ <div class="method-heading">
429
+ <a href="#M000027" class="method-signature">
430
+ <span class="method-name">next</span><span class="method-args">()</span>
431
+ </a>
432
+ </div>
433
+
434
+ <div class="method-description">
435
+ <p><a class="source-toggle" href="#"
436
+ onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
437
+ <div class="method-source-code" id="M000027-source">
438
+ <pre>
439
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 246</span>
440
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
441
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">after</span>(<span class="ruby-keyword kw">self</span>)
442
+ <span class="ruby-keyword kw">end</span>
443
+ </pre>
444
+ </div>
445
+ </div>
446
+ </div>
447
+
448
+ <div id="method-M000026" class="method-detail">
449
+ <a name="M000026"></a>
450
+
451
+ <div class="method-heading">
452
+ <a href="#M000026" class="method-signature">
453
+ <span class="method-name">previous</span><span class="method-args">()</span>
454
+ </a>
455
+ </div>
456
+
457
+ <div class="method-description">
458
+ <p><a class="source-toggle" href="#"
459
+ onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
460
+ <div class="method-source-code" id="M000026-source">
461
+ <pre>
462
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 242</span>
463
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous</span>
464
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">before</span>(<span class="ruby-keyword kw">self</span>)
465
+ <span class="ruby-keyword kw">end</span>
466
+ </pre>
467
+ </div>
468
+ </div>
469
+ </div>
470
+
471
+ <div id="method-M000028" class="method-detail">
472
+ <a name="M000028"></a>
473
+
474
+ <div class="method-heading">
475
+ <a href="#M000028" class="method-signature">
476
+ <span class="method-name">versions_count</span><span class="method-args">()</span>
477
+ </a>
478
+ </div>
479
+
480
+ <div class="method-description">
481
+ <p><a class="source-toggle" href="#"
482
+ onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
483
+ <div class="method-source-code" id="M000028-source">
484
+ <pre>
485
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 250</span>
486
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versions_count</span>
487
+ <span class="ruby-identifier">page</span>.<span class="ruby-identifier">version</span>
488
+ <span class="ruby-keyword kw">end</span>
489
+ </pre>
490
+ </div>
491
+ </div>
492
+ </div>
493
+
494
+
495
+ </div>
496
+
497
+
498
+ </div>
499
+
500
+
501
+ <div id="validator-badges">
502
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
503
+ </div>
504
+
505
+ </body>
506
+ </html>