acts_as_audited_rails3 1.1.1.4
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/.gitignore +4 -0
- data/CHANGELOG +25 -0
- data/LICENSE +19 -0
- data/README +76 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/acts_as_audited.gemspec +90 -0
- data/acts_as_audited_rails3.gemspec +90 -0
- data/doc/classes/Audit.html +407 -0
- data/doc/classes/CollectiveIdea/Acts/Audited/ClassMethods.html +226 -0
- data/doc/classes/CollectiveIdea/Acts/Audited/InstanceMethods.html +330 -0
- data/doc/classes/CollectiveIdea/Acts/Audited/SingletonMethods.html +254 -0
- data/doc/created.rid +1 -0
- data/doc/files/README.html +226 -0
- data/doc/files/lib/acts_as_audited/audit_rb.html +108 -0
- data/doc/files/lib/acts_as_audited/audit_sweeper_rb.html +101 -0
- data/doc/files/lib/acts_as_audited_rb.html +129 -0
- data/doc/fr_class_index.html +30 -0
- data/doc/fr_file_index.html +30 -0
- data/doc/fr_method_index.html +47 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/acts_as_audited/audit.rb +119 -0
- data/lib/acts_as_audited/audit_sweeper.rb +37 -0
- data/lib/acts_as_audited/base.rb +316 -0
- data/lib/acts_as_audited.rb +9 -0
- data/lib/generators/audited_migration/USAGE +7 -0
- data/lib/generators/audited_migration/audited_migration_generator.rb +24 -0
- data/lib/generators/audited_migration/templates/migration.rb +29 -0
- data/lib/generators/audited_migration_update/USAGE +7 -0
- data/lib/generators/audited_migration_update/audited_migration_update_generator.rb +24 -0
- data/lib/generators/audited_migration_update/templates/migration.rb +9 -0
- data/test/acts_as_audited_test.rb +437 -0
- data/test/audit_sweeper_test.rb +31 -0
- data/test/audit_test.rb +179 -0
- data/test/db/database.yml +21 -0
- data/test/db/schema.rb +33 -0
- data/test/test_helper.rb +75 -0
- metadata +152 -0
@@ -0,0 +1,407 @@
|
|
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>Class: Audit</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>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Audit</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/acts_as_audited/audit_rb.html">
|
59
|
+
lib/acts_as_audited/audit.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
ActiveRecord::Base
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
<div id="description">
|
82
|
+
<p>
|
83
|
+
<a href="Audit.html">Audit</a> saves the changes to ActiveRecord models. It
|
84
|
+
has the following attributes:
|
85
|
+
</p>
|
86
|
+
<ul>
|
87
|
+
<li><tt>auditable</tt>: the ActiveRecord model that was changed
|
88
|
+
|
89
|
+
</li>
|
90
|
+
<li><tt>user</tt>: the user that performed the change; a string or an
|
91
|
+
ActiveRecord model
|
92
|
+
|
93
|
+
</li>
|
94
|
+
<li><tt>action</tt>: one of create, update, or delete
|
95
|
+
|
96
|
+
</li>
|
97
|
+
<li><tt>audit_changes</tt>: a serialized hash of all the changes
|
98
|
+
|
99
|
+
</li>
|
100
|
+
<li><tt>created_at</tt>: Time that the change was performed
|
101
|
+
|
102
|
+
</li>
|
103
|
+
</ul>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
|
108
|
+
</div>
|
109
|
+
|
110
|
+
<div id="method-list">
|
111
|
+
<h3 class="section-bar">Methods</h3>
|
112
|
+
|
113
|
+
<div class="name-list">
|
114
|
+
<a href="#M000004">ancestors</a>
|
115
|
+
<a href="#M000002">as_user</a>
|
116
|
+
<a href="#M000008">assign_revision_attributes</a>
|
117
|
+
<a href="#M000001">audited_classes</a>
|
118
|
+
<a href="#M000005">new_attributes</a>
|
119
|
+
<a href="#M000006">old_attributes</a>
|
120
|
+
<a href="#M000007">reconstruct_attributes</a>
|
121
|
+
<a href="#M000003">revision</a>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
|
128
|
+
<!-- if includes -->
|
129
|
+
|
130
|
+
<div id="section">
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
<div id="aliases-list">
|
135
|
+
<h3 class="section-bar">External Aliases</h3>
|
136
|
+
|
137
|
+
<div class="name-list">
|
138
|
+
<table summary="aliases">
|
139
|
+
<tr class="top-aligned-row context-row">
|
140
|
+
<td class="context-item-name">user=</td>
|
141
|
+
<td>-></td>
|
142
|
+
<td class="context-item-value">user_as_model=</td>
|
143
|
+
</tr>
|
144
|
+
<tr class="top-aligned-row context-row">
|
145
|
+
<td class="context-item-name">user_as_string=</td>
|
146
|
+
<td>-></td>
|
147
|
+
<td class="context-item-value">user=</td>
|
148
|
+
</tr>
|
149
|
+
<tr class="top-aligned-row context-row">
|
150
|
+
<td class="context-item-name">user</td>
|
151
|
+
<td>-></td>
|
152
|
+
<td class="context-item-value">user_as_model</td>
|
153
|
+
</tr>
|
154
|
+
<tr class="top-aligned-row context-row">
|
155
|
+
<td class="context-item-name">user_as_string</td>
|
156
|
+
<td>-></td>
|
157
|
+
<td class="context-item-value">user</td>
|
158
|
+
</tr>
|
159
|
+
</table>
|
160
|
+
</div>
|
161
|
+
</div>
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<!-- if method_list -->
|
168
|
+
<div id="methods">
|
169
|
+
<h3 class="section-bar">Public Class methods</h3>
|
170
|
+
|
171
|
+
<div id="method-M000002" class="method-detail">
|
172
|
+
<a name="M000002"></a>
|
173
|
+
|
174
|
+
<div class="method-heading">
|
175
|
+
<a href="#M000002" class="method-signature">
|
176
|
+
<span class="method-name">as_user</span><span class="method-args">(user) {|| ...}</span>
|
177
|
+
</a>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
<div class="method-description">
|
181
|
+
<p>
|
182
|
+
All audits made during the block called will be recorded as made by
|
183
|
+
<tt>user</tt>. This method is hopefully threadsafe, making it ideal for
|
184
|
+
background operations that require audit information.
|
185
|
+
</p>
|
186
|
+
<p><a class="source-toggle" href="#"
|
187
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
188
|
+
<div class="method-source-code" id="M000002-source">
|
189
|
+
<pre>
|
190
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 32</span>
|
191
|
+
32: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">as_user</span>(<span class="ruby-identifier">user</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
192
|
+
33: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-identifier">:acts_as_audited_user</span>] = <span class="ruby-identifier">user</span>
|
193
|
+
34:
|
194
|
+
35: <span class="ruby-keyword kw">yield</span>
|
195
|
+
36:
|
196
|
+
37: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-identifier">:acts_as_audited_user</span>] = <span class="ruby-keyword kw">nil</span>
|
197
|
+
38: <span class="ruby-keyword kw">end</span>
|
198
|
+
</pre>
|
199
|
+
</div>
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
|
203
|
+
<div id="method-M000008" class="method-detail">
|
204
|
+
<a name="M000008"></a>
|
205
|
+
|
206
|
+
<div class="method-heading">
|
207
|
+
<a href="#M000008" class="method-signature">
|
208
|
+
<span class="method-name">assign_revision_attributes</span><span class="method-args">(record, attributes)</span>
|
209
|
+
</a>
|
210
|
+
</div>
|
211
|
+
|
212
|
+
<div class="method-description">
|
213
|
+
<p><a class="source-toggle" href="#"
|
214
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
215
|
+
<div class="method-source-code" id="M000008-source">
|
216
|
+
<pre>
|
217
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 95</span>
|
218
|
+
95: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">assign_revision_attributes</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">attributes</span>)
|
219
|
+
96: <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
|
220
|
+
97: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"#{attr}="</span>)
|
221
|
+
98: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">?</span>
|
222
|
+
99: <span class="ruby-identifier">record</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-identifier">val</span> <span class="ruby-operator">:</span>
|
223
|
+
100: <span class="ruby-identifier">record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{attr}="</span>, <span class="ruby-identifier">val</span>)
|
224
|
+
101: <span class="ruby-keyword kw">end</span>
|
225
|
+
102: <span class="ruby-keyword kw">end</span>
|
226
|
+
103: <span class="ruby-identifier">record</span>
|
227
|
+
104: <span class="ruby-keyword kw">end</span>
|
228
|
+
</pre>
|
229
|
+
</div>
|
230
|
+
</div>
|
231
|
+
</div>
|
232
|
+
|
233
|
+
<div id="method-M000001" class="method-detail">
|
234
|
+
<a name="M000001"></a>
|
235
|
+
|
236
|
+
<div class="method-heading">
|
237
|
+
<a href="#M000001" class="method-signature">
|
238
|
+
<span class="method-name">audited_classes</span><span class="method-args">()</span>
|
239
|
+
</a>
|
240
|
+
</div>
|
241
|
+
|
242
|
+
<div class="method-description">
|
243
|
+
<p><a class="source-toggle" href="#"
|
244
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
245
|
+
<div class="method-source-code" id="M000001-source">
|
246
|
+
<pre>
|
247
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 22</span>
|
248
|
+
22: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">audited_classes</span>
|
249
|
+
23: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">audited_class_names</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">:constantize</span>)
|
250
|
+
24: <span class="ruby-keyword kw">end</span>
|
251
|
+
</pre>
|
252
|
+
</div>
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
|
256
|
+
<div id="method-M000007" class="method-detail">
|
257
|
+
<a name="M000007"></a>
|
258
|
+
|
259
|
+
<div class="method-heading">
|
260
|
+
<a href="#M000007" class="method-signature">
|
261
|
+
<span class="method-name">reconstruct_attributes</span><span class="method-args">(audits) {|attributes if block_given?| ...}</span>
|
262
|
+
</a>
|
263
|
+
</div>
|
264
|
+
|
265
|
+
<div class="method-description">
|
266
|
+
<p><a class="source-toggle" href="#"
|
267
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
268
|
+
<div class="method-source-code" id="M000007-source">
|
269
|
+
<pre>
|
270
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 86</span>
|
271
|
+
86: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reconstruct_attributes</span>(<span class="ruby-identifier">audits</span>)
|
272
|
+
87: <span class="ruby-identifier">attributes</span> = {}
|
273
|
+
88: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">audits</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">audit</span><span class="ruby-operator">|</span>
|
274
|
+
89: <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">audit</span>.<span class="ruby-identifier">new_attributes</span>).<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">:version</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">audit</span>.<span class="ruby-identifier">version</span>)
|
275
|
+
90: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">attributes</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
276
|
+
91: <span class="ruby-keyword kw">end</span>
|
277
|
+
92: <span class="ruby-identifier">block_given?</span> <span class="ruby-value">? </span><span class="ruby-identifier">result</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">attributes</span>
|
278
|
+
93: <span class="ruby-keyword kw">end</span>
|
279
|
+
</pre>
|
280
|
+
</div>
|
281
|
+
</div>
|
282
|
+
</div>
|
283
|
+
|
284
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
285
|
+
|
286
|
+
<div id="method-M000004" class="method-detail">
|
287
|
+
<a name="M000004"></a>
|
288
|
+
|
289
|
+
<div class="method-heading">
|
290
|
+
<a href="#M000004" class="method-signature">
|
291
|
+
<span class="method-name">ancestors</span><span class="method-args">()</span>
|
292
|
+
</a>
|
293
|
+
</div>
|
294
|
+
|
295
|
+
<div class="method-description">
|
296
|
+
<p><a class="source-toggle" href="#"
|
297
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
298
|
+
<div class="method-source-code" id="M000004-source">
|
299
|
+
<pre>
|
300
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 64</span>
|
301
|
+
64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ancestors</span>
|
302
|
+
65: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'version'</span>,
|
303
|
+
66: <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">></span> [<span class="ruby-value str">'auditable_id = ? and auditable_type = ? and version <= ?'</span>,
|
304
|
+
67: <span class="ruby-identifier">auditable_id</span>, <span class="ruby-identifier">auditable_type</span>, <span class="ruby-identifier">version</span>])
|
305
|
+
68: <span class="ruby-keyword kw">end</span>
|
306
|
+
</pre>
|
307
|
+
</div>
|
308
|
+
</div>
|
309
|
+
</div>
|
310
|
+
|
311
|
+
<div id="method-M000005" class="method-detail">
|
312
|
+
<a name="M000005"></a>
|
313
|
+
|
314
|
+
<div class="method-heading">
|
315
|
+
<a href="#M000005" class="method-signature">
|
316
|
+
<span class="method-name">new_attributes</span><span class="method-args">()</span>
|
317
|
+
</a>
|
318
|
+
</div>
|
319
|
+
|
320
|
+
<div class="method-description">
|
321
|
+
<p>
|
322
|
+
Returns a hash of the changed attributes with the new values
|
323
|
+
</p>
|
324
|
+
<p><a class="source-toggle" href="#"
|
325
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
326
|
+
<div class="method-source-code" id="M000005-source">
|
327
|
+
<pre>
|
328
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 71</span>
|
329
|
+
71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_attributes</span>
|
330
|
+
72: (<span class="ruby-identifier">audit_changes</span> <span class="ruby-operator">||</span> {}).<span class="ruby-identifier">inject</span>({}.<span class="ruby-identifier">with_indifferent_access</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attrs</span>,(<span class="ruby-identifier">attr</span>,<span class="ruby-identifier">values</span>)<span class="ruby-operator">|</span>
|
331
|
+
73: <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">values</span>).<span class="ruby-identifier">last</span>
|
332
|
+
74: <span class="ruby-identifier">attrs</span>
|
333
|
+
75: <span class="ruby-keyword kw">end</span>
|
334
|
+
76: <span class="ruby-keyword kw">end</span>
|
335
|
+
</pre>
|
336
|
+
</div>
|
337
|
+
</div>
|
338
|
+
</div>
|
339
|
+
|
340
|
+
<div id="method-M000006" class="method-detail">
|
341
|
+
<a name="M000006"></a>
|
342
|
+
|
343
|
+
<div class="method-heading">
|
344
|
+
<a href="#M000006" class="method-signature">
|
345
|
+
<span class="method-name">old_attributes</span><span class="method-args">()</span>
|
346
|
+
</a>
|
347
|
+
</div>
|
348
|
+
|
349
|
+
<div class="method-description">
|
350
|
+
<p>
|
351
|
+
Returns a hash of the changed attributes with the old values
|
352
|
+
</p>
|
353
|
+
<p><a class="source-toggle" href="#"
|
354
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
355
|
+
<div class="method-source-code" id="M000006-source">
|
356
|
+
<pre>
|
357
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 79</span>
|
358
|
+
79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">old_attributes</span>
|
359
|
+
80: (<span class="ruby-identifier">audit_changes</span> <span class="ruby-operator">||</span> {}).<span class="ruby-identifier">inject</span>({}.<span class="ruby-identifier">with_indifferent_access</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attrs</span>,(<span class="ruby-identifier">attr</span>,<span class="ruby-identifier">values</span>)<span class="ruby-operator">|</span>
|
360
|
+
81: <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">values</span>).<span class="ruby-identifier">first</span>
|
361
|
+
82: <span class="ruby-identifier">attrs</span>
|
362
|
+
83: <span class="ruby-keyword kw">end</span>
|
363
|
+
84: <span class="ruby-keyword kw">end</span>
|
364
|
+
</pre>
|
365
|
+
</div>
|
366
|
+
</div>
|
367
|
+
</div>
|
368
|
+
|
369
|
+
<div id="method-M000003" class="method-detail">
|
370
|
+
<a name="M000003"></a>
|
371
|
+
|
372
|
+
<div class="method-heading">
|
373
|
+
<a href="#M000003" class="method-signature">
|
374
|
+
<span class="method-name">revision</span><span class="method-args">()</span>
|
375
|
+
</a>
|
376
|
+
</div>
|
377
|
+
|
378
|
+
<div class="method-description">
|
379
|
+
<p><a class="source-toggle" href="#"
|
380
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
381
|
+
<div class="method-source-code" id="M000003-source">
|
382
|
+
<pre>
|
383
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited/audit.rb, line 57</span>
|
384
|
+
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">revision</span>
|
385
|
+
58: <span class="ruby-identifier">clazz</span> = <span class="ruby-identifier">auditable_type</span>.<span class="ruby-identifier">constantize</span>
|
386
|
+
59: <span class="ruby-identifier">returning</span> <span class="ruby-identifier">clazz</span>.<span class="ruby-identifier">find_by_id</span>(<span class="ruby-identifier">auditable_id</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">clazz</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span>
|
387
|
+
60: <span class="ruby-constant">Audit</span>.<span class="ruby-identifier">assign_revision_attributes</span>(<span class="ruby-identifier">m</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">reconstruct_attributes</span>(<span class="ruby-identifier">ancestors</span>).<span class="ruby-identifier">merge</span>({<span class="ruby-identifier">:version</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">version</span>}))
|
388
|
+
61: <span class="ruby-keyword kw">end</span>
|
389
|
+
62: <span class="ruby-keyword kw">end</span>
|
390
|
+
</pre>
|
391
|
+
</div>
|
392
|
+
</div>
|
393
|
+
</div>
|
394
|
+
|
395
|
+
|
396
|
+
</div>
|
397
|
+
|
398
|
+
|
399
|
+
</div>
|
400
|
+
|
401
|
+
|
402
|
+
<div id="validator-badges">
|
403
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
404
|
+
</div>
|
405
|
+
|
406
|
+
</body>
|
407
|
+
</html>
|
@@ -0,0 +1,226 @@
|
|
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: CollectiveIdea::Acts::Audited::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">CollectiveIdea::Acts::Audited::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_audited_rb.html">
|
59
|
+
lib/acts_as_audited.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="#M000009">acts_as_audited</a>
|
84
|
+
</div>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
</div>
|
88
|
+
|
89
|
+
|
90
|
+
<!-- if includes -->
|
91
|
+
<div id="includes">
|
92
|
+
<h3 class="section-bar">Included Modules</h3>
|
93
|
+
|
94
|
+
<div id="includes-list">
|
95
|
+
<span class="include-name"><a href="InstanceMethods.html">CollectiveIdea::Acts::Audited::InstanceMethods</a></span>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<div id="section">
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
<!-- if method_list -->
|
109
|
+
<div id="methods">
|
110
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
111
|
+
|
112
|
+
<div id="method-M000009" class="method-detail">
|
113
|
+
<a name="M000009"></a>
|
114
|
+
|
115
|
+
<div class="method-heading">
|
116
|
+
<a href="#M000009" class="method-signature">
|
117
|
+
<span class="method-name">acts_as_audited</span><span class="method-args">(options = {})</span>
|
118
|
+
</a>
|
119
|
+
</div>
|
120
|
+
|
121
|
+
<div class="method-description">
|
122
|
+
<h2>Configuration options</h2>
|
123
|
+
<ul>
|
124
|
+
<li><tt>only</tt> - Only audit the given attributes
|
125
|
+
|
126
|
+
</li>
|
127
|
+
<li><tt>except</tt> - Excludes fields from being saved in the audit log. By
|
128
|
+
default, <a href="ClassMethods.html#M000009">acts_as_audited</a> will audit
|
129
|
+
all but these fields:
|
130
|
+
|
131
|
+
<pre>
|
132
|
+
[self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
|
133
|
+
</pre>
|
134
|
+
<p>
|
135
|
+
You can add to those by passing one or an array of fields to skip.
|
136
|
+
</p>
|
137
|
+
<pre>
|
138
|
+
class User < ActiveRecord::Base
|
139
|
+
acts_as_audited :except => :password
|
140
|
+
end
|
141
|
+
</pre>
|
142
|
+
</li>
|
143
|
+
<li><tt>protect</tt> - If your model uses <tt>attr_protected</tt>, set this to
|
144
|
+
false to prevent Rails from raising an error. If you declare
|
145
|
+
<tt>attr_accessibe</tt> before calling <tt><a
|
146
|
+
href="ClassMethods.html#M000009">acts_as_audited</a></tt>, it will
|
147
|
+
automatically default to false. You only need to explicitly set this if you
|
148
|
+
are calling <tt>attr_accessible</tt> after.
|
149
|
+
|
150
|
+
</li>
|
151
|
+
<li><tt>require_comment</tt> - Ensures that audit_comment is supplied before
|
152
|
+
any create, update or destroy operation.
|
153
|
+
|
154
|
+
<pre>
|
155
|
+
class User < ActiveRecord::Base
|
156
|
+
acts_as_audited :protect => false
|
157
|
+
attr_accessible :name
|
158
|
+
end
|
159
|
+
</pre>
|
160
|
+
</li>
|
161
|
+
</ul>
|
162
|
+
<p><a class="source-toggle" href="#"
|
163
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
164
|
+
<div class="method-source-code" id="M000009-source">
|
165
|
+
<pre>
|
166
|
+
<span class="ruby-comment cmt"># File lib/acts_as_audited.rb, line 70</span>
|
167
|
+
70: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">acts_as_audited</span>(<span class="ruby-identifier">options</span> = {})
|
168
|
+
71: <span class="ruby-comment cmt"># don't allow multiple calls</span>
|
169
|
+
72: <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">CollectiveIdea</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Audited</span><span class="ruby-operator">::</span><span class="ruby-constant">InstanceMethods</span>)
|
170
|
+
73:
|
171
|
+
74: <span class="ruby-identifier">options</span> = {<span class="ruby-identifier">:protect</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">accessible_attributes</span>.<span class="ruby-identifier">nil?</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
172
|
+
75:
|
173
|
+
76: <span class="ruby-identifier">class_inheritable_reader</span> <span class="ruby-identifier">:non_audited_columns</span>
|
174
|
+
77: <span class="ruby-identifier">class_inheritable_reader</span> <span class="ruby-identifier">:auditing_enabled</span>
|
175
|
+
78:
|
176
|
+
79: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only</span>]
|
177
|
+
80: <span class="ruby-identifier">except</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">column_names</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">:to_s</span>)
|
178
|
+
81: <span class="ruby-keyword kw">else</span>
|
179
|
+
82: <span class="ruby-identifier">except</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-value str">'lock_version'</span>, <span class="ruby-value str">'created_at'</span>, <span class="ruby-value str">'updated_at'</span>]
|
180
|
+
83: <span class="ruby-identifier">except</span> <span class="ruby-operator">|=</span> <span class="ruby-constant">Array</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:except</span>]).<span class="ruby-identifier">collect</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">:to_s</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:except</span>]
|
181
|
+
84: <span class="ruby-keyword kw">end</span>
|
182
|
+
85: <span class="ruby-identifier">write_inheritable_attribute</span> <span class="ruby-identifier">:non_audited_columns</span>, <span class="ruby-identifier">except</span>
|
183
|
+
86:
|
184
|
+
87: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:comment_required</span>]
|
185
|
+
88: <span class="ruby-identifier">validates_presence_of</span> <span class="ruby-identifier">:audit_comment</span>
|
186
|
+
89: <span class="ruby-identifier">before_destroy</span> <span class="ruby-identifier">:require_comment</span>
|
187
|
+
90: <span class="ruby-keyword kw">end</span>
|
188
|
+
91:
|
189
|
+
92: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-identifier">:audit_comment</span>
|
190
|
+
93: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">accessible_attributes</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:protect</span>]
|
191
|
+
94: <span class="ruby-identifier">attr_accessible</span> <span class="ruby-identifier">:audit_comment</span>
|
192
|
+
95: <span class="ruby-keyword kw">end</span>
|
193
|
+
96:
|
194
|
+
97: <span class="ruby-identifier">has_many</span> <span class="ruby-identifier">:audits</span>, <span class="ruby-identifier">:as</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:auditable</span>, <span class="ruby-identifier">:order</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{Audit.quoted_table_name}.version"</span>
|
195
|
+
98: <span class="ruby-identifier">attr_protected</span> <span class="ruby-identifier">:audit_ids</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:protect</span>]
|
196
|
+
99: <span class="ruby-constant">Audit</span>.<span class="ruby-identifier">audited_class_names</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>
|
197
|
+
100:
|
198
|
+
101: <span class="ruby-identifier">after_create</span> <span class="ruby-identifier">:audit_create</span>
|
199
|
+
102: <span class="ruby-identifier">before_update</span> <span class="ruby-identifier">:audit_update</span>
|
200
|
+
103: <span class="ruby-identifier">after_destroy</span> <span class="ruby-identifier">:audit_destroy</span>
|
201
|
+
104:
|
202
|
+
105: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-identifier">:version</span>
|
203
|
+
106:
|
204
|
+
107: <span class="ruby-identifier">extend</span> <span class="ruby-constant">CollectiveIdea</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Audited</span><span class="ruby-operator">::</span><span class="ruby-constant">SingletonMethods</span>
|
205
|
+
108: <span class="ruby-identifier">include</span> <span class="ruby-constant">CollectiveIdea</span><span class="ruby-operator">::</span><span class="ruby-constant">Acts</span><span class="ruby-operator">::</span><span class="ruby-constant">Audited</span><span class="ruby-operator">::</span><span class="ruby-constant">InstanceMethods</span>
|
206
|
+
109:
|
207
|
+
110: <span class="ruby-identifier">write_inheritable_attribute</span> <span class="ruby-identifier">:auditing_enabled</span>, <span class="ruby-keyword kw">true</span>
|
208
|
+
111: <span class="ruby-keyword kw">end</span>
|
209
|
+
</pre>
|
210
|
+
</div>
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
|
215
|
+
</div>
|
216
|
+
|
217
|
+
|
218
|
+
</div>
|
219
|
+
|
220
|
+
|
221
|
+
<div id="validator-badges">
|
222
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
</body>
|
226
|
+
</html>
|