No commit activity in last 3 years
No release in over 3 years
Allows to pospose the execution of a code waiting for Active Record transactions, on commit, on rollback or both.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.12
~> 3.4
~> 0.11

Runtime

 Project Readme

FishTransactions NO LONGER MAINTAINED

Fish Transactions allows to add transaction callbacks anywhere.

Installation

Add this line to your application's Gemfile:

gem 'fish_transactions'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fish_transactions

Usage

First you need to include FishTransactions#Callbacks module into the class you want to use it. Once included, you can directly call after_commit or after_rollback with the code you wanna run on such events.

Example

class SomeClass

  include FishTransactions::Callbacks

  # ...

  def some_method
    # ...

    ActiveRecord::Base.transaction do
      # executes some code
      puts "runs within transaction"

      after_commit do

        # things to do after commit
        puts "runs after commit"

      end

      # executes more code
      puts "again runs within transaction"
    end
    # ...

  end

  # ...

end

will output

runs within transaction
again runs within transaction
runs after commit

Please see FishTransactions::Callbacks for more details.

Alternative class methods usage

Since 1.1 version you can also directly use after_* methods as FishTransactions class methods.

Example

class SomeClass

  # ...

  def some_method
    # ...

    ActiveRecord::Base.transaction do
      # executes some code
      puts "runs within transaction"

      FishTransactions.after_commit do

        # things to do after commit
        puts "runs after commit"

      end

      # executes more code
      puts "again runs within transaction"
    end
    # ...

  end

  # ...

end

will output

runs within transaction
again runs within transaction
runs after commit

Contributing

Bug reports and pull requests are welcome on GitHub at beetrack/fish_transactions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Development

This gem is inspired on AR After Transaction gem.

License

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