Git Product home page Git Product logo

ar-audit-tracer's Introduction

ar-audit-tracer

<img src=“https://badge.fury.io/rb/ar-audit-tracer.png” alt=“Gem Version” /> <img src=“https://secure.travis-ci.org/verticonaut/ar-audit-tracer.png” /> <img src=“https://codeclimate.com/github/verticonaut/ar-audit-tracer.png” />

Summary

ar-audit-tracer patches ActiveRecord so modifiers of a record can be traked on saving (insert/update). It works exactly like ‘timestamps’ (see usage below).

The new version 2.0.0 works now for Rails 4.0 with Ruby 1.9.3 and 2.0.0. Use the version 1.0.2 for Rails ~3.0 with Ruby 1.8.7 or higher.

Note

The migration helpers changed. The column statement is now named t.authorstamps instead of t.authors. Similar the changing a table is named add_authorstamp. The columns generated are still named the same - so they are calles created_by and updated_by.

Installation

Add below to your Gemfile and run the bundle command

gem 'ar-audit-tracer'

Usage

Migration

In a models migration add:

t.authorstamps

This will add columns created_by and updated_by of type :string to your model.

In case you want to use another type, simply pass the type as argument, e.g.

t.authorstamps(:integer)

By default the columns are mandatory (:null => false). If you have existing models you want to change you have to pass the option :null => true, update the values in the new attributes columns and add another migration to change the column to :null => false if required. Note: If you pass options you have to pass the type as well - sample migration statments:

add_authorstamps(:your_table_name, :string, :null => true)

or

change_table :your_table_name do |t|
  t.authorstamps(:integer, :null => true)
end

Note

The authorstamps methods are simple conveniance methods (as regular timestamp methods are). You can simply add columns named created_by and updated_by using regular migration statements.<p/> You can name the attributes created_by_id and updated_by_id. If these columns are detected they are filled as well.

Configuration

All you need to do is to set the current author such as e.g:

Concern::Audit::Author.current="bad_man"

Each ActiveRecord save or update then will set the respetive attributes created_by and updated_by automatically, whereas the modifier is set to the same value as the creator on model creation.

In a Rails Application you would set the author as described above in a before_filter. Concern::Audit::Author stores the author in a Thread-Local variable.

Additional Notes

In case you need associations to a respective Author Model you have to set them up yourselfs.

Changelog

Version 2.0.0

  • Works for Rails4 with Ruby1.9.3 and Ruby 2.0.0

  • Works now not only for created_by and updated_by, but as well for attributes created_by_id and updated_by_id

Version 1.0.2

  • Fixed migrations so option can be passed

ar-audit-tracer's People

Contributors

awd-switzerland avatar verticonaut avatar verticonaut-g avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.