Module: Auditable::Auditing::ClassMethods
- Defined in:
- lib/auditable/auditing.rb
Instance Attribute Summary collapse
-
#audited_attributes ⇒ Object
Get the list of methods to track over record saves, including those inherited from parent.
Instance Method Summary collapse
-
#audit(*options) ⇒ Object
Set the list of methods to track over record saves.
Instance Attribute Details
#audited_attributes ⇒ Object
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(*options) ⇒ 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 |
# File 'lib/auditable/auditing.rb', line 25 def audit(*) has_many :audits, :class_name => "Auditable::Audit", :as => :auditable after_create {|record| record.snap!(:action => "create")} after_update {|record| record.snap!(:action => "update")} self.audited_attributes = Array.wrap end |