ericperko-acts_as_audited 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ acts_as_audited_plugin.sqlite3.db
2
+ test/debug.log
3
+ coverage/
4
+ pkg
@@ -0,0 +1,26 @@
1
+ acts_as_audited ChangeLog
2
+ -------------------------------------------------------------------------------
3
+ * 2010-07-07 - Renamed the audit.version field to audit.audit_version to avoid conflicts with an existing model's names
4
+ * 2009-01-27 - Store old and new values for updates, and store all attributes on destroy.
5
+ Refactored revisioning methods to work as expected
6
+ * 2008-10-10 - changed to make it work in development mode
7
+ * 2008-04-19 - refactored to make compatible with dirty tracking in edge rails
8
+ and to stop storing both old and new values in a single audit
9
+ * 2008-04-18 - Fix NoMethodError when trying to access the :previous revision
10
+ on a model that doesn't have previous revisions [Alex Soto]
11
+ * 2008-03-21 - added #changed_attributes to get access to the changes before a
12
+ save [Chris Parker]
13
+ * 2007-12-16 - Added #revision_at for retrieving a revision from a specific
14
+ time [Jacob Atzen]
15
+ * 2007-12-16 - Fix error when getting revision from audit with no changes
16
+ [Geoffrey Wiseman]
17
+ * 2007-12-16 - Remove dependency on acts_as_list
18
+ * 2007-06-17 - Added support getting previous revisions
19
+ * 2006-11-17 - Replaced use of singleton User.current_user with cache sweeper
20
+ implementation for auditing the user that made the change
21
+ * 2006-11-17 - added migration generator
22
+ * 2006-08-14 - incorporated changes from Michael Schuerig to write_attribute
23
+ that saves the new value after every change and not just the
24
+ first, and performs proper type-casting before doing comparisons
25
+ * 2006-08-14 - The "changes" are now saved as a serialized hash
26
+ * 2006-07-21 - initial version
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2008 Brandon Keepers - Collective Idea
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,76 @@
1
+ = acts_as_audited
2
+
3
+ acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table.
4
+
5
+ The purpose of this fork is to rename audit fields to avoid conflicts with existing attributes of models in our webapp
6
+
7
+ == Installation
8
+
9
+ script/plugin install git://github.com/ericperko/acts_as_audited.git
10
+
11
+ * Generate the migration
12
+
13
+ * If installing without a previous version of acts_as_audited or you do not mind overwriting your audits table:
14
+
15
+ script/generate audited_migration add_audits_table
16
+
17
+ * If upgrading from a version of acts_as_audited that does not contain comment functionality:
18
+
19
+ script/generate audited_migration_update update_audits_table
20
+
21
+ * After running one of the generators:
22
+
23
+ rake db:migrate
24
+
25
+ == Usage
26
+
27
+ Declare <tt>acts_as_audited</tt> on your models:
28
+
29
+ class User < ActiveRecord::Base
30
+ acts_as_audited :except => [:password, :mistress]
31
+ end
32
+
33
+ Within a web request, will automatically record the user that made the change if your controller has a <tt>current_user</tt> method. Comments can be added to an audit by setting model.audit_comments
34
+ before create/update/destroy. If the :comment_required option is given to acts_as_audited,
35
+ the save/update/destroy action will fail with add an error on model.audit_comment and triggering a
36
+ transaction rollback if model.audit_comment is nil.
37
+
38
+ To record a user in the audits outside of a web request, you can use <tt>as_user</tt>:
39
+
40
+ Audit.as_user(user) do
41
+ # Perform changes on audited models
42
+ end
43
+
44
+ == Caveats
45
+
46
+ If your model declares +attr_accessible+ after +acts_as_audited+, you need to set +:protect+ to false. acts_as_audited uses +attr_protected+ internally to prevent malicious users from unassociating your audits, and Rails does not allow both +attr_protected+ and +attr_accessible+. It will default to false if +attr_accessible+ is called before +acts_as_audited+, but needs to be explicitly set if it is called after.
47
+
48
+ class User < ActiveRecord::Base
49
+ acts_as_audited :protect => false
50
+ attr_accessible :name
51
+ end
52
+
53
+ == Compatability
54
+
55
+ acts_as_audited works with Rails 2.1 or later.
56
+
57
+ == Getting Help
58
+
59
+ Join the mailing list for getting help or offering suggestions:
60
+ http://groups.google.com/group/acts_as_audited
61
+
62
+ == Contributing
63
+
64
+ Contributions are always welcome. Checkout the latest code on GitHub:
65
+ http://github.com/collectiveidea/acts_as_audited
66
+
67
+ Please include tests with your patches. There are a few gems required to run the tests:
68
+ $ gem install multi_rails
69
+ $ gem install thoughtbot-shoulda jnunemaker-matchy --source http://gems.github.com
70
+
71
+ Make sure the tests pass against all versions of Rails since 2.1:
72
+
73
+ $ rake test:multi_rails:all
74
+
75
+ Please report bugs or feature suggestions on GitHub:
76
+ http://github.com/collectiveidea/acts_as_audited/issues
@@ -0,0 +1,57 @@
1
+ require 'rake'
2
+ require 'load_multi_rails_rake_tasks'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ desc 'Default: run tests.'
7
+ task :default => :test
8
+
9
+ begin
10
+ require 'jeweler'
11
+ Jeweler::Tasks.new do |gem|
12
+ gem.name = "acts_as_audited"
13
+ gem.summary = %Q{ActiveRecord extension that logs all changes to your models in an audits table}
14
+ gem.email = "brandon@opensoul.org"
15
+ gem.homepage = "http://github.com/collectiveidea/acts_as_audited"
16
+ gem.authors = ["Brandon Keepers"]
17
+ gem.add_dependency 'activerecord', '>=2.1'
18
+ gem.add_development_dependency "thoughtbot-shoulda"
19
+ gem.add_development_dependency "jnunemaker-matchy"
20
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
+ end
22
+ # Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
25
+ end
26
+
27
+ desc 'Test the acts_as_audited plugin'
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = true
32
+ end
33
+
34
+ task :test => :check_dependencies
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/*_test.rb'
41
+ test.verbose = true
42
+ test.rcov_opts = %w(--exclude test,/usr/lib/ruby,/Library/Ruby,$HOME/.gem --sort coverage)
43
+ end
44
+ rescue LoadError
45
+ task :rcov do
46
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
+ end
48
+ end
49
+
50
+ desc 'Generate documentation for the acts_as_audited plugin.'
51
+ Rake::RDocTask.new(:rdoc) do |rdoc|
52
+ rdoc.rdoc_dir = 'doc'
53
+ rdoc.title = 'acts_as_audited'
54
+ rdoc.options << '--line-numbers' << '--inline-source'
55
+ rdoc.rdoc_files.include('README')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.2
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ericperko-acts_as_audited}
8
+ s.version = "1.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brandon Keepers", "Eric Perko"]
12
+ s.date = %q{2010-04-03}
13
+ s.email = %q{brandon@opensoul.org}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "CHANGELOG",
21
+ "LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "acts_as_audited.gemspec",
26
+ "generators/audited_migration/USAGE",
27
+ "generators/audited_migration/audited_migration_generator.rb",
28
+ "generators/audited_migration/templates/migration.rb",
29
+ "generators/audited_migration_update/audited_migration_update_generator.rb",
30
+ "generators/audited_migration_update/templates/migration.rb",
31
+ "generators/audited_migration_update/USAGE",
32
+ "init.rb",
33
+ "lib/acts_as_audited.rb",
34
+ "lib/acts_as_audited/audit.rb",
35
+ "lib/acts_as_audited/audit_sweeper.rb",
36
+ "rails/init.rb",
37
+ "test/acts_as_audited_test.rb",
38
+ "test/audit_sweeper_test.rb",
39
+ "test/audit_test.rb",
40
+ "test/db/database.yml",
41
+ "test/db/schema.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/ericperko/acts_as_audited}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.6}
48
+ s.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
49
+ s.test_files = [
50
+ "test/acts_as_audited_test.rb",
51
+ "test/audit_sweeper_test.rb",
52
+ "test/audit_test.rb",
53
+ "test/db/schema.rb",
54
+ "test/test_helper.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.1"])
63
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ s.add_development_dependency(%q<jnunemaker-matchy>, [">= 0"])
65
+ else
66
+ s.add_dependency(%q<activerecord>, [">= 2.1"])
67
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
68
+ s.add_dependency(%q<jnunemaker-matchy>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<activerecord>, [">= 2.1"])
72
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
73
+ s.add_dependency(%q<jnunemaker-matchy>, [">= 0"])
74
+ end
75
+ end
76
+
@@ -0,0 +1,7 @@
1
+ Description:
2
+ The audited migration generator creates a migration to add the audits table.
3
+
4
+ Example:
5
+ ./script/generate audited_migration add_audits_table
6
+
7
+ This will create a migration in db/migrate/. Run "rake db:migrate" to update your database.
@@ -0,0 +1,7 @@
1
+ class AuditedMigrationGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ class <%= class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :audits, :force => true do |t|
4
+ t.column :auditable_id, :integer
5
+ t.column :auditable_type, :string
6
+ t.column :user_id, :integer
7
+ t.column :user_type, :string
8
+ t.column :username, :string
9
+ t.column :action, :string
10
+ t.column :changes, :text
11
+ t.column :audit_version, :integer, :default => 0
12
+ t.column :comment, :string
13
+ t.column :created_at, :datetime
14
+ end
15
+
16
+ add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
17
+ add_index :audits, [:user_id, :user_type], :name => 'user_index'
18
+ add_index :audits, :created_at
19
+ end
20
+
21
+ def self.down
22
+ drop_table :audits
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ Description:
2
+ The audited migration generator creates a migration to update the audits table to allow for audit comments. It should only be used if upgrading acts_as_audited from a version which does not permit audit comments
3
+
4
+ Example:
5
+ ./script/generate audited_migration_upgrade update_audits_table
6
+
7
+ This will create a migration in db/migrate/. Run "rake db:migrate" to update your database.
@@ -0,0 +1,7 @@
1
+ class AuditedMigrationUpdateGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :audits, :comment, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :audits, :comment
8
+ end
9
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
@@ -0,0 +1,277 @@
1
+ # Copyright (c) 2006 Brandon Keepers
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module CollectiveIdea #:nodoc:
23
+ module Acts #:nodoc:
24
+ # Specify this act if you want changes to your model to be saved in an
25
+ # audit table. This assumes there is an audits table ready.
26
+ #
27
+ # class User < ActiveRecord::Base
28
+ # acts_as_audited
29
+ # end
30
+ #
31
+ # To store an audit comment set model.audit_comment to your comment before
32
+ # a create, update or destroy operation.
33
+ #
34
+ # See <tt>CollectiveIdea::Acts::Audited::ClassMethods#acts_as_audited</tt>
35
+ # for configuration options
36
+ module Audited #:nodoc:
37
+ CALLBACKS = [:audit_create, :audit_update, :audit_destroy]
38
+
39
+ def self.included(base) # :nodoc:
40
+ base.extend ClassMethods
41
+ end
42
+
43
+ module ClassMethods
44
+ # == Configuration options
45
+ #
46
+ #
47
+ # * +only+ - Only audit the given attributes
48
+ # * +except+ - Excludes fields from being saved in the audit log.
49
+ # By default, acts_as_audited will audit all but these fields:
50
+ #
51
+ # [self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
52
+ # You can add to those by passing one or an array of fields to skip.
53
+ #
54
+ # class User < ActiveRecord::Base
55
+ # acts_as_audited :except => :password
56
+ # end
57
+ # * +protect+ - If your model uses +attr_protected+, set this to false to prevent Rails from
58
+ # raising an error. If you declare +attr_accessibe+ before calling +acts_as_audited+, it
59
+ # will automatically default to false. You only need to explicitly set this if you are
60
+ # calling +attr_accessible+ after.
61
+ #
62
+ # * +require_comment+ - Ensures that audit_comment is supplied before
63
+ # any create, update or destroy operation.
64
+ #
65
+ # class User < ActiveRecord::Base
66
+ # acts_as_audited :protect => false
67
+ # attr_accessible :name
68
+ # end
69
+ #
70
+ def acts_as_audited(options = {})
71
+ # don't allow multiple calls
72
+ return if self.included_modules.include?(CollectiveIdea::Acts::Audited::InstanceMethods)
73
+
74
+ options = {:protect => accessible_attributes.nil?}.merge(options)
75
+
76
+ class_inheritable_reader :non_audited_columns
77
+ class_inheritable_reader :auditing_enabled
78
+
79
+ if options[:only]
80
+ except = self.column_names - options[:only].flatten.map(&:to_s)
81
+ else
82
+ except = [self.primary_key, inheritance_column, 'lock_version',
83
+ 'created_at', 'updated_at', 'created_on', 'updated_on']
84
+ except |= Array(options[:except]).collect(&:to_s) if options[:except]
85
+ end
86
+ write_inheritable_attribute :non_audited_columns, except
87
+
88
+ if options[:comment_required]
89
+ validates_presence_of :audit_comment
90
+ before_destroy :require_comment
91
+ end
92
+
93
+ attr_accessor :audit_comment
94
+ unless accessible_attributes.nil? || options[:protect]
95
+ attr_accessible :audit_comment
96
+ end
97
+
98
+ has_many :audits, :as => :auditable, :order => "#{Audit.quoted_table_name}.audit_version"
99
+ attr_protected :audit_ids if options[:protect]
100
+ Audit.audited_class_names << self.to_s
101
+
102
+ after_create :audit_create if !options[:on] || (options[:on] && options[:on].include?(:create))
103
+ before_update :audit_update if !options[:on] || (options[:on] && options[:on].include?(:update))
104
+ after_destroy :audit_destroy if !options[:on] || (options[:on] && options[:on].include?(:destroy))
105
+
106
+ attr_accessor :audit_version
107
+
108
+ extend CollectiveIdea::Acts::Audited::SingletonMethods
109
+ include CollectiveIdea::Acts::Audited::InstanceMethods
110
+
111
+ write_inheritable_attribute :auditing_enabled, true
112
+ end
113
+ end
114
+
115
+ module InstanceMethods
116
+
117
+ # Temporarily turns off auditing while saving.
118
+ def save_without_auditing
119
+ without_auditing { save }
120
+ end
121
+
122
+ # Executes the block with the auditing callbacks disabled.
123
+ #
124
+ # @foo.without_auditing do
125
+ # @foo.save
126
+ # end
127
+ #
128
+ def without_auditing(&block)
129
+ self.class.without_auditing(&block)
130
+ end
131
+
132
+ # Gets an array of the revisions available
133
+ #
134
+ # user.revisions.each do |revision|
135
+ # user.name
136
+ # user.audit_version
137
+ # end
138
+ #
139
+ def revisions(from_version = 1)
140
+ audits = self.audits.find(:all, :conditions => ['audit_version >= ?', from_version])
141
+ return [] if audits.empty?
142
+ revision = self.audits.find_by_audit_version(from_version).revision
143
+ Audit.reconstruct_attributes(audits) {|attrs| revision.revision_with(attrs) }
144
+ end
145
+
146
+ # Get a specific revision specified by the version number, or +:previous+
147
+ def revision(version)
148
+ revision_with Audit.reconstruct_attributes(audits_to(version))
149
+ end
150
+
151
+ def revision_at(date_or_time)
152
+ audits = self.audits.find(:all, :conditions => ["created_at <= ?", date_or_time])
153
+ revision_with Audit.reconstruct_attributes(audits) unless audits.empty?
154
+ end
155
+
156
+ def audited_attributes
157
+ attributes.except(*non_audited_columns)
158
+ end
159
+
160
+ protected
161
+
162
+ def revision_with(attributes)
163
+ returning self.dup do |revision|
164
+ revision.send :instance_variable_set, '@attributes', self.attributes_before_type_cast
165
+ Audit.assign_revision_attributes(revision, attributes)
166
+
167
+ # Remove any association proxies so that they will be recreated
168
+ # and reference the correct object for this revision. The only way
169
+ # to determine if an instance variable is a proxy object is to
170
+ # see if it responds to certain methods, as it forwards almost
171
+ # everything to its target.
172
+ for ivar in revision.instance_variables
173
+ proxy = revision.instance_variable_get ivar
174
+ if !proxy.nil? and proxy.respond_to? :proxy_respond_to?
175
+ revision.instance_variable_set ivar, nil
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ private
182
+
183
+ def audited_changes
184
+ changed_attributes.except(*non_audited_columns).inject({}) do |changes,(attr, old_value)|
185
+ changes[attr] = [old_value, self[attr]]
186
+ changes
187
+ end
188
+ end
189
+
190
+ def audits_to(version = nil)
191
+ if version == :previous
192
+ version = if self.audit_version
193
+ self.audit_version - 1
194
+ else
195
+ previous = audits.find(:first, :offset => 1,
196
+ :order => "#{Audit.quoted_table_name}.audit_version DESC")
197
+ previous ? previous.audit_version : 1
198
+ end
199
+ end
200
+ audits.find(:all, :conditions => ['audit_version <= ?', version])
201
+ end
202
+
203
+ def audit_create
204
+ write_audit(:action => 'create', :changes => audited_attributes,
205
+ :comment => audit_comment)
206
+ end
207
+
208
+ def audit_update
209
+ unless (changes = audited_changes).empty?
210
+ write_audit(:action => 'update', :changes => changes,
211
+ :comment => audit_comment)
212
+ end
213
+ end
214
+
215
+ def audit_destroy
216
+ write_audit(:action => 'destroy', :changes => audited_attributes,
217
+ :comment => audit_comment)
218
+ end
219
+
220
+ def write_audit(attrs)
221
+ self.audit_comment = nil
222
+ self.audits.create attrs if auditing_enabled
223
+ end
224
+
225
+ def require_comment
226
+ if audit_comment.blank?
227
+ errors.add(:audit_comment, "Comment required before destruction")
228
+ return false
229
+ end
230
+ end
231
+
232
+ CALLBACKS.each do |attr_name|
233
+ alias_method "#{attr_name}_callback".to_sym, attr_name
234
+ end
235
+
236
+ def empty_callback #:nodoc:
237
+ end
238
+
239
+ end # InstanceMethods
240
+
241
+ module SingletonMethods
242
+ # Returns an array of columns that are audited. See non_audited_columns
243
+ def audited_columns
244
+ self.columns.select { |c| !non_audited_columns.include?(c.name) }
245
+ end
246
+
247
+ # Executes the block with auditing disabled.
248
+ #
249
+ # Foo.without_auditing do
250
+ # @foo.save
251
+ # end
252
+ #
253
+ def without_auditing(&block)
254
+ auditing_was_enabled = auditing_enabled
255
+ disable_auditing
256
+ returning(block.call) { enable_auditing if auditing_was_enabled }
257
+ end
258
+
259
+ def disable_auditing
260
+ write_inheritable_attribute :auditing_enabled, false
261
+ end
262
+
263
+ def enable_auditing
264
+ write_inheritable_attribute :auditing_enabled, true
265
+ end
266
+
267
+ # All audit operations during the block are recorded as being
268
+ # made by +user+. This is not model specific, the method is a
269
+ # convenience wrapper around #Audit.as_user.
270
+ def audit_as( user, &block )
271
+ Audit.as_user( user, &block )
272
+ end
273
+
274
+ end
275
+ end
276
+ end
277
+ end