46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/audited/auditor.rb', line 46
def notifiably_audited(options = {})
return if self.included_modules.include?(Audited::Auditor::AuditedInstanceMethods)
class_attribute :non_audited_columns, :instance_writer => false
class_attribute :auditing_enabled, :instance_writer => false
class_attribute :audit_associated_with, :instance_writer => false
class_attribute :audit_alert_to, :instance_writer => false
class_attribute :audit_alert_for, :instance_writer => false
class_attribute :audit_title, :instance_writer => false
class_attribute :audit_create_comment, :instance_writer => false
class_attribute :audit_update_comment, :instance_writer => false
if options[:only]
except = self.column_names - options[:only].flatten.map(&:to_s)
else
except = default_ignored_attributes + Audited.ignored_attributes
except |= Array(options[:except]).collect(&:to_s) if options[:except]
end
self.non_audited_columns = except
self.audit_associated_with = options[:associated_with]
self.audit_alert_to = options[:alert_to] || :assigned_to
self.audit_alert_for = options[:alert_for] || nil
self.audit_title = options[:title] || :name
self. = options[:create_comment] || "New <<here>> has been created"
self. = options[:update_comment] || "Values of <<here>> has been updated"
if options[:comment_required]
validates_presence_of :audit_comment, :if => :auditing_enabled
before_destroy :require_comment
end
attr_accessor :audit_comment
unless options[:allow_mass_assignment]
attr_accessible :audit_comment
end
has_many :audits, :as => :auditable, :class_name => Audited.audit_class.name
Audited.audit_class.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))
before_destroy :audit_destroy if !options[:on] || (options[:on] && options[:on].include?(:destroy))
define_callbacks :audit
set_callback :audit, :after, :after_audit, :if => lambda { self.respond_to?(:after_audit) }
attr_accessor :version
extend Audited::Auditor::AuditedClassMethods
include Audited::Auditor::AuditedInstanceMethods
self.auditing_enabled = true
end
|