Skip to content

A Rails engine to help you track regressions to ApplicationRecord models leveraging paper_trail

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
MIT-LICENSE
Notifications You must be signed in to change notification settings

lidijarad/regressions

Repository files navigation

Regressions

If you want to track regressions across your ActiveRecord models, then you can leverage paper_trail in conjunction with this Rails::Engine to view and inspect regressions.

Usage

Follow instructions to install and setup the paper_trail gem. Make sure you add the versions table to your application's database.

Once paper_trail has been setup, add the has_paper_trail method to your model. Then on the following line, add the opsbox_track_regressions method to the model. Order is important, since validations are run to ensure has_paper_trail has been correctly setup.

class User < ApplicationRecord
  has_paper_trail
  opsbox_track_regressions
end

Track regressions on specific columns

You are able to specify specific columns you wish to track. This will add a tracked_columns attribute to your model when you pass in the the only option as follows:

class User < ApplicationRecord
  has_paper_trail
  opsbox_track_regressions only: [:name, :address]
end

Alert if your model has a regression

A notify_changes method can be added to the model. Here you can define a specific action/alert that needs to happen if any of the model's tracked_columns change as follows:

class User < ApplicationRecord
  has_paper_trail
  opsbox_track_regressions only: [:name, :address]

  def notify_changes
    # Rails.logger.info('Regression detected')
    # Sentry.capture_message('Regression detected')
    # send an email
    # notify another application
  end
end

Mount Regressions::Engine in your application's routes.rb file

If you wish to utilise the views defined in this engine to inspect changes to your model, then you need to mount the engine in your application's routes.rb file at a desired path.

  mount Regressions::Engine => "/regressions"

Installation

Add this line to your application's Gemfile:

gem 'regressions'

And then execute:

$ bundle

Or install it yourself as:

$ gem install regressions

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

About

A Rails engine to help you track regressions to ApplicationRecord models leveraging paper_trail

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
MIT-LICENSE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published