120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/acts_as_audited.rb', line 120
def acts_as_audited(options = {})
return if self.included_modules.include?(CollectiveIdea::Acts::Audited::InstanceMethods)
options = {:protect => accessible_attributes.nil?}.merge(options)
class_inheritable_reader :non_audited_columns
class_inheritable_reader :auditing_enabled
class_inheritable_reader :manually_set_columns
class_inheritable_reader :if_condition
class_inheritable_reader :unless_condition
if options[:only]
except = self.column_names - options[:only].flatten.map(&:to_s)
else
except = [self.primary_key, inheritance_column, 'lock_version',
'created_at', 'updated_at', 'created_on', 'updated_on']
except |= Array(options[:except]).collect(&:to_s) if options[:except]
end
write_inheritable_attribute :non_audited_columns, except
write_inheritable_attribute :manually_set_columns, options.reject {|k, v| reserved_options.include?(k) }
write_inheritable_attribute :if_condition, options.delete(:if)
write_inheritable_attribute :unless_condition, options.delete(:unless)
has_many :audits, :as => :auditable, :order => "#{Audit.quoted_table_name}.version", :dependent => :nullify
attr_protected :audit_ids if options[:protect]
Audit.audited_class_names << self.to_s
after_create :audit_create if !options[:on] || (options[:on] && options[:on].include?(:create))
before_update :audit_update if !options[:on] || (options[:on] && options[:on].include?(:update))
after_destroy :audit_destroy if !options[:on] || (options[:on] && options[:on].include?(:destroy))
attr_accessor :version
extend CollectiveIdea::Acts::Audited::SingletonMethods
include CollectiveIdea::Acts::Audited::InstanceMethods
write_inheritable_attribute :auditing_enabled, true
end
|