https://github.com/thheller/auditor
Audit Reports for your Models
https://github.com/thheller/auditor
Last synced: 8 months ago
JSON representation
Audit Reports for your Models
- Host: GitHub
- URL: https://github.com/thheller/auditor
- Owner: thheller
- License: mit
- Created: 2011-03-04T14:16:10.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-08-19T09:44:51.000Z (almost 15 years ago)
- Last Synced: 2025-02-10T11:11:43.181Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 172 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
- Audit: auditor.gemspec
Awesome Lists containing this project
README
= Auditor
Record Model changes with ease.
You wish, I use this in one of my projects and wanted to use
it in another, so this extraction came to be.
Dont use if you are not me.
Only records changes happening inside an Audit.process block,
there is a RackApp middleware to include to record any changes
triggered by any http request.
= Usage
Rails3:
config/application.rb
config.middleware.use '::Auditor::RackApp'
any model that should record changes:
class Membership < ActiveRecord::Base
include ::Auditor::Callbacks
end
Save some report info?
class ApplicationController < ...
before_filter :set_audit_infos
def set_audit_infos
Auditor.current do |audit|
audit.info[:method] = request.method
audit.info[:ip] = request.ip
audit.info[:referer] = request.referer
audit.user = current_user
end
true
end
end
Use in background daemons?
require 'socket' # not required, but i like hostnames
SomeModel.where('expires_at < ?', Time.now).each do |it|
Audit.process do |audit|
audit.info[:pid] = Process.pid
audit.info[:hostname] = Socket.gethostname
it.expired!
end
end
= Migration
ActiveRecord Models:
Auditor::AuditReport
Auditor::AuditChanges
class CreateAuditTables < ActiveRecord::Migration
def self.up
create_table :audit_reports do |t|
t.string :uuid, :null => false, :length => 32
t.string :user_type
t.integer :user_id
t.text :info
t.integer :num_changes, :null => false
t.boolean :success, :null => false
t.string :error
t.text :error_message
t.text :error_detail
t.timestamp :began_at, :null => false
t.timestamp :finished_at, :null => false
end
create_table :audit_changes do |t|
t.integer :audit_report_id, :null => false
t.string :model_type, :null => false
t.integer :model_id, :null => false
t.string :action, :null => false
t.text :audited_changes
t.timestamp :created_at
end
end
def self.down
end
end
This project rocks anyways and uses MIT-LICENSE.