0.0
The project is in a healthy, maintained state
ActiveCapture allows you to save captures of ActiveRecord records, including their nested associations, and restore them at any point. Useful for auditing, backups, and rollback functionality.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.0
 Project Readme

ActiveCapture

ActiveCapture is a Ruby on Rails gem that allows you to capture and restore records along with their nested associations. It supports saving data to JSON files and restoring it later, making it useful for auditing, backups, rollback functionality, or seeding data.

Installation

Add this line to your application's Gemfile:

 gem 'active_capture'

And then execute:

 $ bundle install

Or install it yourself as:

 $ gem install active_capture

Usage

Capture a Record Without Associations

user = User.find(1)
ActiveCapture::Capture.take(user)

This will create a JSON file in the snapshots/ directory.

Capture a Record With Associations

user = User.find(1)
ActiveCapture::Capture.take(user, associations: [:posts, :comments])

This will include all associated posts and comments of the user.

Capture a Record With Custom Filename

user = User.find(1)
ActiveCapture::Capture.take(user, filename: "custom_user_data.json")

The file will be saved as snapshots/custom_user_data.json.

Restore a Record

user = User.find(1)
ActiveCapture::Capture.restore(user, filename: "user/1_20250329013025.json")

This will restore the user's state from the given file.

Restore a Record With Specific Associations

user = User.find(1)
ActiveCapture::Capture.restore(user, associations: [:posts])

Only the specified associations (posts) will be restored.

Usage In Rake Task

task restore_user: :environment do
  user = User.find(1)
  ActiveCapture::Capture.restore(user, filename: "user_backup.json")
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bhawsartanmay/active_capture.

License

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