module Audited::Audit::ClassMethods

Public Instance Methods

as_user(user) { || ... } click to toggle source

All audits made during the block called will be recorded as made by user. This method is hopefully threadsafe, making it ideal for background operations that require audit information.

# File lib/audited/audit.rb, line 30
def as_user(user, &block)
  Thread.current[:audited_user] = user

  yieldval = yield

  Thread.current[:audited_user] = nil

  yieldval
end
assign_revision_attributes(record, attributes) click to toggle source

@private

# File lib/audited/audit.rb, line 51
def assign_revision_attributes(record, attributes)
  attributes.each do |attr, val|
    record = record.dup if record.frozen?

    if record.respond_to?("#{attr}=")
      record.attributes.has_key?(attr.to_s) ?
        record[attr] = val :
        record.send("#{attr}=", val)
    end
  end
  record
end
audited_classes() click to toggle source

Returns the list of classes that are being audited

# File lib/audited/audit.rb, line 23
def audited_classes
  audited_class_names.map(&:constantize)
end
reconstruct_attributes(audits) { |attributes| ... } click to toggle source

@private

# File lib/audited/audit.rb, line 41
def reconstruct_attributes(audits)
  attributes = {}
  result = audits.collect do |audit|
    attributes.merge!(audit.new_attributes).merge!(:version => audit.version)
    yield attributes if block_given?
  end
  block_given? ? result : attributes
end
setup_audit() click to toggle source
# File lib/audited/audit.rb, line 9
def setup_audit
  belongs_to :auditable,  :polymorphic => true
  belongs_to :user,       :polymorphic => true
  belongs_to :associated, :polymorphic => true

  before_create :set_version_number, :set_audit_user

  cattr_accessor :audited_class_names
  self.audited_class_names = Set.new

  attr_accessible :action, :audited_changes, :comment, :associated
end