Module: CollectiveIdea::Acts::Audited
- Defined in:
- lib/acts_as_audited.rb
Overview
Specify this act if you want changes to your model to be saved in an audit table. This assumes there is an audits table ready.
class User < ActiveRecord::Base
acts_as_audited
end
See CollectiveIdea::Acts::Audited::ClassMethods#acts_as_audited
for configuration options
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, SingletonMethods
Constant Summary collapse
- CALLBACKS =
:nodoc:
[:audit_create, :audit_update, :audit_destroy]
- @@human_model =
:user
- @@additional_attributes =
[]
- @@use_observer =
:true
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
-
.included(base) ⇒ Object
:nodoc:.
- .modify_audit_model ⇒ Object
Class Method Details
.configure {|_self| ... } ⇒ Object
Call this method to modify defaults in your initializers.
57 58 59 60 61 |
# File 'lib/acts_as_audited.rb', line 57 def configure yield self modify_audit_model end |
.included(base) ⇒ Object
:nodoc:
91 92 93 |
# File 'lib/acts_as_audited.rb', line 91 def included(base) # :nodoc: base.extend ClassMethods end |
.modify_audit_model ⇒ Object
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 |
# File 'lib/acts_as_audited.rb', line 63 def modify_audit_model Audit.class_eval do belongs_to @@human_model, :polymorphic => true [@@additional_attributes].flatten.each do |attrib| belongs_to attrib, :class_name => @@human_model.to_s.classify, :foreign_key => "#{attrib}_id" end alias_method :user_as_model=, "#{@@human_model}=".to_sym alias_method "#{@@human_model}=".to_sym, :user_as_string= alias_method :user_as_model, @@human_model alias_method @@human_model, :user_as_string def set_audit_user self.send(@@human_model, Thread.current[:acts_as_audited_user]) if Thread.current[:acts_as_audited_user] nil # prevent stopping callback chains end end if @@use_observer ::ActionController::Base.class_eval do cache_sweeper :audit_sweeper end Audit.add_observer(AuditSweeper.instance) end end |