Module: CollectiveIdea::Acts::Audited::ClassMethods
- Defined in:
- lib/acts_as_audited_rails3/base.rb
Instance Method Summary collapse
-
#acts_as_audited(options = {}) ⇒ Object
Configuration options.
Instance Method Details
#acts_as_audited(options = {}) ⇒ Object
Configuration options
-
only
- Only audit the given attributes -
except
- Excludes fields from being saved in the audit log. By default, acts_as_audited will audit all but these fields:[self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
You can add to those by passing one or an array of fields to skip.
class User < ActiveRecord::Base acts_as_audited :except => :password end
-
protect
- set to false to raise an error if your model usesattr_protected
, by default it is true -
require_comment
- Ensures that audit_comment is supplied before any create, update or destroy operation.class User < ActiveRecord::Base acts_as_audited :protect => false attr_accessible :name end
-
full_model_enabled
- in YAML, save the current state of the record to the audits table -
full_model_enabled
- in YAML, save the current state of the record to the audits table
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 109 110 111 112 113 114 |
# File 'lib/acts_as_audited_rails3/base.rb', line 69 def acts_as_audited( = {}) # don't allow multiple calls return if self.included_modules.include?(CollectiveIdea::Acts::Audited::InstanceMethods) class_inheritable_reader :auditing_full_model_enabled write_inheritable_attribute :auditing_full_model_enabled, (false || [:full_model_enabled]) = {:protect => true}.merge() class_inheritable_reader :non_audited_columns class_inheritable_reader :auditing_enabled if [:only] except = self.column_names - [:only].flatten.map(&:to_s) else except = [self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at', 'created_on', 'updated_on', 'created_by', 'updated_by'] except |= Array([:except]).collect(&:to_s) if [:except] end write_inheritable_attribute :non_audited_columns, ['audits'] + (except || []) if [:comment_required] validates_presence_of :audit_comment before_destroy :require_comment end attr_accessor :audit_comment unless accessible_attributes.nil? || [:protect] attr_accessible :audit_comment end has_many :audits, :as => :auditable, :order => "#{Audit.quoted_table_name}.version" attr_protected :audit_ids if [:protect] Audit.audited_class_names << self.to_s after_create :audit_create if ![:on] || ([:on] && [:on].include?(:create)) before_update :audit_update if ![:on] || ([:on] && [:on].include?(:update)) before_destroy :audit_destroy if ![:on] || ([:on] && [:on].include?(:destroy)) attr_accessor :version extend CollectiveIdea::Acts::Audited::SingletonMethods include CollectiveIdea::Acts::Audited::InstanceMethods write_inheritable_attribute :auditing_enabled, true end |