This is a gemified plugin for Ruby on Rails applications that also use ElasticSearch as part of their stack. This gem adds change tracking features to the Rails app models, so that setting up an activity feed for that model (or more models) becomes easier.
It is based on ActiveRecord callbacks. As the record is created, updated or deleted, its changes and also its associated records' data are stored in an ElasticSearch index.
This gem was created with Ruby 2.7, Rails 6.0.3 and ElasticSearch 7.7. Forwards and backwards compatibility is at this stage unknown.
Add this line to your application's Gemfile:
gem 'track-record', git: 'https://github.com/leap2digital/track-record', branch: 'main'And then execute:
$ bundleYou can use the generator below to create an initializer for ElasticSearch client config:
$ rails generate track_record:elasticsearch_configNOTE: You can find an example of a docker-compose.yml we use for the gem's development with Ruby and Elasticsearch, this might help you set up a development environment for your app that is compatible with the gem.
To start tracking changes in your Rails models simply require the gem's module and include it in your model.rb:
require 'track_record'
class YourModel < ApplicationRecord
include TrackRecord
# Your model code
endTo track who made modifications to the model we use a global variable called $custom_current_user. You can set the authenticated user to this variable in your authentication logic and the gem will include its info on the changes track record.
Bug reports and pull requests are welcome on GitHub at https://github.com/leap2digital/track-record.
The gem is available as open source under the terms of the MIT License.