ActiveAudit
ActiveAudit is a library for auditing record changes.
Installation
Add this line to your application's Gemfile:
gem 'active_audit'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_audit
Table of Contents
Configurations
Options:
- auditor
- source
rails generate active_audit:install
will generate the following active_audit.rb
file:
# config/initalizers/active_audit.rb
ActiveAudit.configure do |config|
# option = default
config.auditor = :current_user
config.source = :app
end
# NOTE:
# Will also generate the following files:
# app/models/audit.rb
# db/migrate/*_create_audits.rb
Usage
user = User.first.update(name: "bill")
Audit.record!(user, :update, source: "api", remote_ip: "123.12.123.123")
# OR:
class Comment < ActiveRecord::Base
include ActiveAudit::Auditable
after_create :trigger_audit_create!
after_update :trigger_audit_update!
after_destroy :trigger_audit_destroy!
end
comment = Comment.create!(body: "Foobar comment")
Audit.first #=> #<Audit id: 1, auditable_id: 1, auditable_type: "Comment", user_id: 1, source: 0, version: 0, action: "create", revisions: {"body"=>[nil, "Foobar"], "user_id"=>[nil, 1], "created_at"=>[nil, 2015-09-30 19:48:48 UTC], "updated_at"=>[nil, 2015-09-30 19:48:48 UTC], "id"=>[nil, 1]}, comment: "Foobar comment", remote_ip: nil, remote_uuid: nil, created_at: "2015-09-30 19:48:48", updated_at: "2015-09-30 19:48:48">
Contributing
- Fork it ( https://github.com/[my-github-username]/active_audit/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request