@@ -19,6 +19,10 @@ module Auditor #:nodoc:
1919    CALLBACKS  =  [ :audit_create ,  :audit_update ,  :audit_destroy ] 
2020
2121    module  ClassMethods 
22+       def  audit_class 
23+         audit_class_name &.safe_constantize  || Audited . audit_class 
24+       end 
25+ 
2226      # == Configuration options 
2327      # 
2428      # 
@@ -67,20 +71,23 @@ def audited(options = {})
6771
6872        class_attribute  :audit_associated_with ,  instance_writer : false 
6973        class_attribute  :audited_options ,  instance_writer : false 
74+         class_attribute  :audit_class_name ,  instance_writer : false 
75+ 
7076        attr_accessor  :audit_version ,  :audit_comment 
7177
7278        self . audited_options  =  options 
7379        normalize_audited_options 
7480
7581        self . audit_associated_with  =  audited_options [ :associated_with ] 
82+         self . audit_class_name  =  audited_options [ :audit_class_name ] 
7683
7784        if  audited_options [ :comment_required ] 
7885          validate  :presence_of_audit_comment 
7986          before_destroy  :require_comment  if  audited_options [ :on ] . include? ( :destroy ) 
8087        end 
8188
82-         has_many  :audits ,  ->  {  order ( version : :asc )  } ,  as : :auditable ,  class_name : Audited . audit_class . name ,  inverse_of : :auditable 
83-         Audited . audit_class . audited_class_names  << to_s 
89+         has_many  :audits ,  ->  {  order ( version : :asc )  } ,  as : :auditable ,  class_name : audit_class . name ,  inverse_of : :auditable 
90+         audit_class . audited_class_names  << to_s 
8491
8592        after_create  :audit_create  if  audited_options [ :on ] . include? ( :create ) 
8693        before_update  :audit_update  if  audited_options [ :on ] . include? ( :update ) 
@@ -96,8 +103,8 @@ def audited(options = {})
96103        enable_auditing 
97104      end 
98105
99-       def  has_associated_audits 
100-         has_many  :associated_audits ,  as : :associated ,  class_name : Audited . audit_class . name 
106+       def  has_associated_audits ( audit_class_name :  Audited . audit_class . name ) 
107+         has_many  :associated_audits ,  as : :associated ,  class_name : audit_class_name 
101108      end 
102109    end 
103110
@@ -159,14 +166,14 @@ def revisions(from_version = 1)
159166      # Returns nil for versions greater than revisions count 
160167      def  revision ( version ) 
161168        if  version  == :previous  || audits . last . version  >= version 
162-           revision_with  Audited . audit_class . reconstruct_attributes ( audits_to ( version ) ) 
169+           revision_with  audit_class . reconstruct_attributes ( audits_to ( version ) ) 
163170        end 
164171      end 
165172
166173      # Find the oldest revision recorded prior to the date/time provided. 
167174      def  revision_at ( date_or_time ) 
168175        audits  =  self . audits . up_until ( date_or_time ) 
169-         revision_with  Audited . audit_class . reconstruct_attributes ( audits )  unless  audits . empty? 
176+         revision_with  audit_class . reconstruct_attributes ( audits )  unless  audits . empty? 
170177      end 
171178
172179      # List of attributes that are audited. 
@@ -177,7 +184,7 @@ def audited_attributes
177184
178185      # Returns a list combined of record audits and associated audits. 
179186      def  own_and_associated_audits 
180-         Audited . audit_class . unscoped 
187+         audit_class . unscoped 
181188          . where ( "(auditable_type = :type AND auditable_id = :id) OR (associated_type = :type AND associated_id = :id)" , 
182189            type : self . class . base_class . name ,  id : id ) 
183190          . order ( created_at : :desc ) 
@@ -206,7 +213,7 @@ def revision_with(attributes)
206213          revision . send  :instance_variable_set ,  "@destroyed" ,  false 
207214          revision . send  :instance_variable_set ,  "@_destroyed" ,  false 
208215          revision . send  :instance_variable_set ,  "@marked_for_destruction" ,  false 
209-           Audited . audit_class . assign_revision_attributes ( revision ,  attributes ) 
216+           audit_class . assign_revision_attributes ( revision ,  attributes ) 
210217
211218          # Remove any association proxies so that they will be recreated 
212219          # and reference the correct object for this revision. The only way 
@@ -431,7 +438,7 @@ def enable_auditing
431438      # convenience wrapper around 
432439      # @see Audit#as_user. 
433440      def  audit_as ( user ,  &block ) 
434-         Audited . audit_class . as_user ( user ,  &block ) 
441+         audit_class . as_user ( user ,  &block ) 
435442      end 
436443
437444      def  auditing_enabled 
0 commit comments