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,336 @@
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::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::ActMethods::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="#M000018">create_versioned_table</a>&nbsp;&nbsp;
84
+ <a href="#M000019">drop_versioned_table</a>&nbsp;&nbsp;
85
+ <a href="#M000017">versioned_class</a>&nbsp;&nbsp;
86
+ <a href="#M000016">versioned_columns</a>&nbsp;&nbsp;
87
+ <a href="#M000021">without_locking</a>&nbsp;&nbsp;
88
+ <a href="#M000020">without_revision</a>&nbsp;&nbsp;
89
+ </div>
90
+ </div>
91
+
92
+ </div>
93
+
94
+
95
+ <!-- if includes -->
96
+
97
+ <div id="section">
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+ <!-- if method_list -->
107
+ <div id="methods">
108
+ <h3 class="section-bar">Public Instance methods</h3>
109
+
110
+ <div id="method-M000018" class="method-detail">
111
+ <a name="M000018"></a>
112
+
113
+ <div class="method-heading">
114
+ <a href="#M000018" class="method-signature">
115
+ <span class="method-name">create_versioned_table</span><span class="method-args">(create_table_options = {})</span>
116
+ </a>
117
+ </div>
118
+
119
+ <div class="method-description">
120
+ <p>
121
+ Rake migration task to create the versioned table using options passed to
122
+ acts_as_versioned
123
+ </p>
124
+ <p><a class="source-toggle" href="#"
125
+ onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
126
+ <div class="method-source-code" id="M000018-source">
127
+ <pre>
128
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 408</span>
129
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_versioned_table</span>(<span class="ruby-identifier">create_table_options</span> = {})
130
+ <span class="ruby-comment cmt"># create version column in main table if it does not exist</span>
131
+ <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">content_columns</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">version_column</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-value str">'lock_version'</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> }
132
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">version_column</span>, <span class="ruby-identifier">:integer</span>
133
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reset_column_information</span>
134
+ <span class="ruby-keyword kw">end</span>
135
+
136
+ <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">table_exists?</span>(<span class="ruby-identifier">versioned_table_name</span>)
137
+
138
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">create_table</span>(<span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">create_table_options</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
139
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> <span class="ruby-identifier">versioned_foreign_key</span>, <span class="ruby-identifier">:integer</span>
140
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> <span class="ruby-identifier">version_column</span>, <span class="ruby-identifier">:integer</span>
141
+ <span class="ruby-keyword kw">end</span>
142
+
143
+ <span class="ruby-keyword kw">self</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>
144
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">col</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">col</span>.<span class="ruby-identifier">type</span>,
145
+ <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">limit</span>,
146
+ <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">default</span>,
147
+ <span class="ruby-identifier">:scale</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">scale</span>,
148
+ <span class="ruby-identifier">:precision</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">col</span>.<span class="ruby-identifier">precision</span>
149
+ <span class="ruby-keyword kw">end</span>
150
+
151
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">type_col</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">inheritance_column</span>]
152
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_column</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">versioned_inheritance_column</span>, <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">type</span>,
153
+ <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">limit</span>,
154
+ <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">default</span>,
155
+ <span class="ruby-identifier">:scale</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">scale</span>,
156
+ <span class="ruby-identifier">:precision</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">type_col</span>.<span class="ruby-identifier">precision</span>
157
+ <span class="ruby-keyword kw">end</span>
158
+
159
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">add_index</span> <span class="ruby-identifier">versioned_table_name</span>, <span class="ruby-identifier">versioned_foreign_key</span>
160
+ <span class="ruby-keyword kw">end</span>
161
+ </pre>
162
+ </div>
163
+ </div>
164
+ </div>
165
+
166
+ <div id="method-M000019" class="method-detail">
167
+ <a name="M000019"></a>
168
+
169
+ <div class="method-heading">
170
+ <a href="#M000019" class="method-signature">
171
+ <span class="method-name">drop_versioned_table</span><span class="method-args">()</span>
172
+ </a>
173
+ </div>
174
+
175
+ <div class="method-description">
176
+ <p>
177
+ Rake migration task to drop the versioned table
178
+ </p>
179
+ <p><a class="source-toggle" href="#"
180
+ onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
181
+ <div class="method-source-code" id="M000019-source">
182
+ <pre>
183
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 442</span>
184
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">drop_versioned_table</span>
185
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">drop_table</span> <span class="ruby-identifier">versioned_table_name</span>
186
+ <span class="ruby-keyword kw">end</span>
187
+ </pre>
188
+ </div>
189
+ </div>
190
+ </div>
191
+
192
+ <div id="method-M000017" class="method-detail">
193
+ <a name="M000017"></a>
194
+
195
+ <div class="method-heading">
196
+ <a href="#M000017" class="method-signature">
197
+ <span class="method-name">versioned_class</span><span class="method-args">()</span>
198
+ </a>
199
+ </div>
200
+
201
+ <div class="method-description">
202
+ <p>
203
+ Returns an instance of the dynamic versioned model
204
+ </p>
205
+ <p><a class="source-toggle" href="#"
206
+ onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
207
+ <div class="method-source-code" id="M000017-source">
208
+ <pre>
209
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 403</span>
210
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versioned_class</span>
211
+ <span class="ruby-identifier">const_get</span> <span class="ruby-identifier">versioned_class_name</span>
212
+ <span class="ruby-keyword kw">end</span>
213
+ </pre>
214
+ </div>
215
+ </div>
216
+ </div>
217
+
218
+ <div id="method-M000016" class="method-detail">
219
+ <a name="M000016"></a>
220
+
221
+ <div class="method-heading">
222
+ <a href="#M000016" class="method-signature">
223
+ <span class="method-name">versioned_columns</span><span class="method-args">()</span>
224
+ </a>
225
+ </div>
226
+
227
+ <div class="method-description">
228
+ <p>
229
+ Returns an array of columns that are versioned. See non_versioned_columns
230
+ </p>
231
+ <p><a class="source-toggle" href="#"
232
+ onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
233
+ <div class="method-source-code" id="M000016-source">
234
+ <pre>
235
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 398</span>
236
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">versioned_columns</span>
237
+ <span class="ruby-ivar">@versioned_columns</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">non_versioned_columns</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span>) }
238
+ <span class="ruby-keyword kw">end</span>
239
+ </pre>
240
+ </div>
241
+ </div>
242
+ </div>
243
+
244
+ <div id="method-M000021" class="method-detail">
245
+ <a name="M000021"></a>
246
+
247
+ <div class="method-heading">
248
+ <a href="#M000021" class="method-signature">
249
+ <span class="method-name">without_locking</span><span class="method-args">(&amp;block)</span>
250
+ </a>
251
+ </div>
252
+
253
+ <div class="method-description">
254
+ <p>
255
+ Turns off optimistic locking for the duration of the block
256
+ </p>
257
+ <pre>
258
+ Foo.without_locking do
259
+ @foo.save
260
+ end
261
+ </pre>
262
+ <p><a class="source-toggle" href="#"
263
+ onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
264
+ <div class="method-source-code" id="M000021-source">
265
+ <pre>
266
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 474</span>
267
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_locking</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
268
+ <span class="ruby-identifier">current</span> = <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span>
269
+ <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>
270
+ <span class="ruby-keyword kw">begin</span>
271
+ <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
272
+ <span class="ruby-keyword kw">ensure</span>
273
+ <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">lock_optimistically</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>
274
+ <span class="ruby-keyword kw">end</span>
275
+ <span class="ruby-keyword kw">end</span>
276
+ </pre>
277
+ </div>
278
+ </div>
279
+ </div>
280
+
281
+ <div id="method-M000020" class="method-detail">
282
+ <a name="M000020"></a>
283
+
284
+ <div class="method-heading">
285
+ <a href="#M000020" class="method-signature">
286
+ <span class="method-name">without_revision</span><span class="method-args">(&amp;block)</span>
287
+ </a>
288
+ </div>
289
+
290
+ <div class="method-description">
291
+ <p>
292
+ Executes the block with the versioning callbacks disabled.
293
+ </p>
294
+ <pre>
295
+ Foo.without_revision do
296
+ @foo.save
297
+ end
298
+ </pre>
299
+ <p><a class="source-toggle" href="#"
300
+ onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
301
+ <div class="method-source-code" id="M000020-source">
302
+ <pre>
303
+ <span class="ruby-comment cmt"># File lib/acts_as_versioned.rb, line 452</span>
304
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">without_revision</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
305
+ <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
306
+ <span class="ruby-constant">CALLBACKS</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span>
307
+ <span class="ruby-identifier">alias_method</span> <span class="ruby-node">&quot;orig_#{attr_name}&quot;</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">attr_name</span>
308
+ <span class="ruby-identifier">alias_method</span> <span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">:empty_callback</span>
309
+ <span class="ruby-keyword kw">end</span>
310
+ <span class="ruby-keyword kw">end</span>
311
+ <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
312
+ <span class="ruby-keyword kw">ensure</span>
313
+ <span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
314
+ <span class="ruby-constant">CALLBACKS</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span>
315
+ <span class="ruby-identifier">alias_method</span> <span class="ruby-identifier">attr_name</span>, <span class="ruby-node">&quot;orig_#{attr_name}&quot;</span>.<span class="ruby-identifier">to_sym</span>
316
+ <span class="ruby-keyword kw">end</span>
317
+ <span class="ruby-keyword kw">end</span>
318
+ <span class="ruby-keyword kw">end</span>
319
+ </pre>
320
+ </div>
321
+ </div>
322
+ </div>
323
+
324
+
325
+ </div>
326
+
327
+
328
+ </div>
329
+
330
+
331
+ <div id="validator-badges">
332
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
333
+ </div>
334
+
335
+ </body>
336
+ </html>