No commit activity in last 3 years
No release in over 3 years
A Ruby on Rails plugin which provides hash with changes committed to the database when the changes hash is already cleared.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 3.2.1
 Project Readme

Committed Changes Build Status


A Ruby on Rails plugin which provides hash with changes committed to the database.

What problem does it solve ?

It's useful when you want to trigger a callback depend on changed attributes after data is committed to the database.

Normally you would do that in after_commit callback, the problem is that changes hash is already cleared.

This is where committed_changes hash comes in.

Installation

Add this to your Gemfile and run bundle install

gem 'committed_changes'

Usage

class Vhost < ActiveRecord::Base
  include CommittedChanges
  after_commit :reconfigure_server, :if => :domains_changed_and_committed?

  def reconfigure_server
    # launch background job
  end
end

foo = Vhost.first
foo.domains = "new.example.com"
foo.save

foo.changes #=> {}
foo.committed_changes #=> {"domains" => ["old.example.com", "new.example.com"]}
foo.domains_changed_and_committed? #=> true

Contributions

To fetch & test the library for development, do:

$ git clone https://github.com/wijet/committed_changes
$ cd committed_changes
$ bundle

Running tests

# Preparing test database
$ cd test/dummy && rake db:migrate && rake db:test:prepare
$ cd ../..
# Running tests
$ bundle exec rake test

If you want to contribute, please:

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Send me a pull request on Github.

This project rocks and uses MIT-LICENSE.