Plugins - super_transaction

StarAdd to favorites

SuperTransaction allows you to save and destroy objects just as you normally would, but under the safety of a database transaction. It extends upon the built in Rails transaction method to cut duplication of what I find myself repeating all over when using transactions.

Examples

  user = User.new(:login => "login", :password => "password")
  book = Book.new(:title => "title")
  page = Page.new(:summary => "summary")

Pass super_transaction a list of the objects that must pass for this transaction to be committed. Note: Make sure you pass these.

  book.user = user
  page.book = book

  ok = super_transaction(user, book, page) do
        user.save
        book.save
        page.save
  end
  ok                            #=> true

super_transaction always returns true or false. As long as you pass the correct objects as parameters, true means a COMMIT took place, false means a ROLLBACK took place.

So the idea is you can write the procedure the same way you would if you weren’t using a transaction. But, you get all of the benefits that you would if you had rolled your own transaction call and accounted for all of the error/exception/validation handling for free.

For convenience, #super_transaction is defined in Object as well and just passes along to ActiveRecord::Base.super_transaction, which allows you to just call super_transaction anywhere.

See README for comparison with regular #transaction

Joe Noon

http://code.stat.im/repos/plugins/super_transaction/tags/0.9/README

http://code.stat.im/repos/plugins/super_transaction/tags/0.9

Rails' (MIT)

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?