module FileTransactions

Constants

VERSION

Public Class Methods

transaction(&block) click to toggle source

This method runs the block inside a transaction

Examples

FileTransactions.transaction do
  CreateFileCommand.execute('new_file') { 'hello' }
  ChangeFileCommand.execute('new_file') { 'world' }
end

FileTransactions.transaction do
  CreateFileCommand.execute('new_file') { 'hello' }
  DeleteFileCommand.execute('some_file')

  # An exception will make the transaction be rolled back. E.g
  # 'new_file' will be removed again and 'some_file' will be restored
  raise "foobar"
end

# Create an alias for FileTransactions
FT = FileTransactions

FT.transaction do
  CreateFileCommand.execute('new_file') { 'hello' }

  FT.transaction do
    ChangeFileCommand.execute('new_file') { 'world' }

    # This rolls back the current transaction but not the outer transaction
    raise FT::Rollback
  end
end
# File lib/file_transactions.rb, line 45
def self.transaction(&block)
  Transaction.run(&block)
end