module Audited::Auditor::ClassMethods
def audited(options = {})
end
end
self.status == 'active'
def active?
audited :if => :active?
class User < ActiveRecord::Base
* +unless+ - Only audit the model when the given function returns false
* +if+ - Only audit the model when the given function returns true
end
audited redacted: :password, redaction_value: SecureRandom.uuid
class User < ActiveRecord::Base
to the redaction_value option.
To store values as something other than '[REDACTED]', pass an argument
password is changed, without saving the actual password in the log.
will not. This is useful, for example, if you wish to audit when a
* +redacted+ - Changes to these fields will be logged, but the values
def audited(options = {}) audited? ? update_audited_options(options) : set_audit(options) end
def audited?
def audited? included_modules.include?(Audited::Auditor::AuditedInstanceMethods) end
def has_associated_audits
def has_associated_audits has_many :associated_audits, as: :associated, class_name: Audited.audit_class.name end
def set_audit(options)
def set_audit(options) extend Audited::Auditor::AuditedClassMethods include Audited::Auditor::AuditedInstanceMethods class_attribute :audit_associated_with, instance_writer: false class_attribute :audited_options, instance_writer: false attr_accessor :audit_version, :audit_comment set_audited_options(options) if audited_options[:comment_required] validate :presence_of_audit_comment before_destroy :require_comment if audited_options[:on].include?(:destroy) end has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: Audited.audit_class.name, inverse_of: :auditable Audited.audit_class.audited_class_names << to_s after_create :audit_create if audited_options[:on].include?(:create) before_update :audit_update if audited_options[:on].include?(:update) after_touch :audit_touch if audited_options[:on].include?(:touch) && ::ActiveRecord::VERSION::MAJOR >= 6 before_destroy :audit_destroy if audited_options[:on].include?(:destroy) # Define and set after_audit and around_audit callbacks. This might be useful if you want # to notify a party after the audit has been created or if you want to access the newly-created # audit. define_callbacks :audit set_callback :audit, :after, :after_audit, if: lambda { respond_to?(:after_audit, true) } set_callback :audit, :around, :around_audit, if: lambda { respond_to?(:around_audit, true) } enable_auditing end
def set_audited_options(options)
def set_audited_options(options) self.audited_options = options normalize_audited_options self.audit_associated_with = audited_options[:associated_with] end
def update_audited_options(new_options)
def update_audited_options(new_options) previous_audit_options = self.audited_options set_audited_options(new_options) self.reset_audited_columns end