Module: Auditable::Auditing::ClassMethods

Defined in:
lib/auditable/auditing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#audited_attributesObject

Get the list of methods to track over record saves, including those inherited from parent



9
10
11
12
13
14
15
16
# File 'lib/auditable/auditing.rb', line 9

def audited_attributes
  attrs =  @audited_attributes || []
  # handle STI case: include parent's audited_attributes
  if superclass != ActiveRecord::Base and superclass.respond_to?(:audited_attributes)
    attrs.push(*superclass.audited_attributes)
  end
  attrs
end

Instance Method Details

#audit(*args) ⇒ Object

Set the list of methods to track over record saves

Example:

class Survey < ActiveRecord::Base
  audit :page_count, :question_ids
end


25
26
27
28
29
30
31
32
33
34
# File 'lib/auditable/auditing.rb', line 25

def audit(*args)
  options = args.extract_options!
  options[:class_name] ||= "Auditable::Audit"
  options[:as] = :auditable
  has_many :audits, options
  after_create {|record| record.snap!(:action => "create")}
  after_update {|record| record.snap!(:action => "update")}

  self.audited_attributes = Array.wrap args
end