Code Monkey home page Code Monkey logo

paper_trail-globalid's Introduction

PaperTrailGlobalid

Code Climate Build Status

This gem is an extension to paper_trail gem https://github.com/airblade/paper_trail. That means you need to pre install paper_trail gem. This gem will add one more method actor to instances of PaperTrail::Version that will return you the ActiveRecord object who was responsible for change.

Supported Rails

This Gem only support >= rails 4.1.0 and above versions.

Installation

  1. Add PaperTrailGlobalid to your Gemfile.

gem 'paper_trail-globalid'

  1. And then execute:
bundle install

Basic Usage

Basically this gem works on stroring global_id to whodunnit field of PaperTrail::Version table. As this is an additional extension installed, this will not hinder / break existing paper_trail functionalities.

widget = Widget.find 42
widget.versions               # [<PaperTrail::Version>, <PaperTrail::Version>, ...]
v = widget.versions.last

Now you can also store object to PaperTrail.whodunnit=, and if object will be instance of ActiveRecord::Base it will store the global id in the version's whodunnit column.

And you can also retrieve the actually object later just by using method actor.

admin = Admin.find(1)                       # <Admin:0x007fa2df9a5590>

PaperTrail.whodunnit = admin
PaperTrail.actor                            # <Admin:0x007fa2df9a5590> actual object

widget.update_attributes :name => 'Wibble'
widget.versions.last.whodunnit              # "gid://app/Admin/1"
widget.versions.last.actor                  # retruns the actuall object

Method actor will return the whodunnit value if we pass value another than ActiveRecord object.

PaperTrail.whodunnit = 'admin_name'
PaperTrail.actor                            # "admin_name"

widget.update_attributes :name => 'Wibble'
widget.versions.last.whodunnit              # "admin_name"
widget.versions.last.actor                  # "admin_name"

Contributing

  1. Fork it ( https://github.com/[my-github-username]/paper_trail-globalid/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

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.