lib/audited/auditor.rb in audited-5.1.0 vs lib/audited/auditor.rb in audited-5.2.0
- old
+ new
@@ -77,12 +77,12 @@
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, inverse_of: :auditable
- Audited.audit_model.audited_class_names << to_s
+ 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)
before_destroy :audit_destroy if audited_options[:on].include?(:destroy)
@@ -95,11 +95,11 @@
enable_auditing
end
def has_associated_audits
- has_many :associated_audits, as: :associated, class_name: Audited.audit_model.name
+ has_many :associated_audits, as: :associated, class_name: Audited.audit_class.name
end
end
module AuditedInstanceMethods
REDACTED = "[REDACTED]"
@@ -157,18 +157,18 @@
# Get a specific revision specified by the version number, or +:previous+
# Returns nil for versions greater than revisions count
def revision(version)
if version == :previous || audits.last.version >= version
- revision_with Audited.audit_model.reconstruct_attributes(audits_to(version))
+ revision_with Audited.audit_class.reconstruct_attributes(audits_to(version))
end
end
# Find the oldest revision recorded prior to the date/time provided.
def revision_at(date_or_time)
audits = self.audits.up_until(date_or_time)
- revision_with Audited.audit_model.reconstruct_attributes(audits) unless audits.empty?
+ revision_with Audited.audit_class.reconstruct_attributes(audits) unless audits.empty?
end
# List of attributes that are audited.
def audited_attributes
audited_attributes = attributes.except(*self.class.non_audited_columns)
@@ -177,12 +177,12 @@
normalize_enum_changes(audited_attributes)
end
# Returns a list combined of record audits and associated audits.
def own_and_associated_audits
- Audited.audit_model.unscoped.where(auditable: self)
- .or(Audited.audit_model.unscoped.where(associated: self))
+ Audited.audit_class.unscoped.where(auditable: self)
+ .or(Audited.audit_class.unscoped.where(associated: self))
.order(created_at: :desc)
end
# Combine multiple audits into one.
def combine_audits(audits_to_combine)
@@ -210,11 +210,11 @@
revision.send :instance_variable_set, "@persisted", !destroyed?
revision.send :instance_variable_set, "@readonly", false
revision.send :instance_variable_set, "@destroyed", false
revision.send :instance_variable_set, "@_destroyed", false
revision.send :instance_variable_set, "@marked_for_destruction", false
- Audited.audit_model.assign_revision_attributes(revision, attributes)
+ Audited.audit_class.assign_revision_attributes(revision, attributes)
# Remove any association proxies so that they will be recreated
# and reference the correct object for this revision. The only way
# to determine if an instance variable is a proxy object is to
# see if it responds to certain methods, as it forwards almost
@@ -453,10 +453,10 @@
# All audit operations during the block are recorded as being
# made by +user+. This is not model specific, the method is a
# convenience wrapper around
# @see Audit#as_user.
def audit_as(user, &block)
- Audited.audit_model.as_user(user, &block)
+ Audited.audit_class.as_user(user, &block)
end
def auditing_enabled
class_auditing_enabled && Audited.auditing_enabled
end