Snapcher
Snapcher is an ORM extension that logs changes to specific columns to your model.
When a change is made to a specific column, the difference between before and after the change is obtained and saved.
To make it easier for analysts, save the table name, column name, and data before and after changes as separate columns.
The name of this gem comes from one of Hideo Kojima's game works, "Snatcher".
It was the first of his game works to introduce cinematic direction, and "Snapcher" is also the first of my gem works.
Supported
Snapcher supports Ruby versions:
Snapcher supports Rails versions:
Supported ORMs
Snapcher is currently ActiveRecord-only.
Installation
Add the gem to your Gemfile:
gem "snapcher"
Then, from your Rails app directory, create the scannings
table:
$ rails generate snapcher:install
$ rails db:migrate
Usage
Simply call scanning
on your models.
Use column_name:
to select the column you want to log.
class User < ActiveRecord::Base
scanning column_name: "name"
end
By default, whenever a user is created, updated or destroyed, a new scanning is created.
user = User.create!(name: "Gillian Seed")
user.scannings.count
user.update!(name: "Mika Slayton")
user.scannings.count
user.destroy
user.scannings.count
Scanning contain information regarding what action was taken on the model and what changes were made.
user.update!(name: "Mika Slayton")
snapcher = user.scannings.last
snapcher.action
snapcher.before_params
snapcher.after_params
If the "Snatcher" column you want to capture is not user_id, you can specify this.
class User < ActiveRecord::Base
scanning column_name: "name", snatch_user: "id"
end