Module: FileTransactions
- Defined in:
- lib/file_transactions.rb,
lib/file_transactions/error.rb,
lib/file_transactions/version.rb,
lib/file_transactions/transaction.rb,
lib/file_transactions/base_command.rb,
lib/file_transactions/move_file_command.rb,
lib/file_transactions/change_file_command.rb,
lib/file_transactions/create_file_command.rb,
lib/file_transactions/delete_file_command.rb,
lib/file_transactions/create_directory_command.rb
Defined Under Namespace
Classes: BaseCommand, ChangeFileCommand, CreateDirectoryCommand, CreateFileCommand, DeleteFileCommand, Error, MoveFileCommand, Rollback, Transaction
Constant Summary collapse
- VERSION =
"1.1.4"
Class Method Summary collapse
-
.transaction(&block) ⇒ Object
This method runs the block inside a transaction.
Class Method Details
.transaction(&block) ⇒ Object
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
45 46 47 |
# File 'lib/file_transactions.rb', line 45 def self.transaction(&block) Transaction.run(&block) end |