Class: DbAgile::Core::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/dbagile/core/transaction.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Transaction

Creates a Transaction instance



11
12
13
# File 'lib/dbagile/core/transaction.rb', line 11

def initialize(connection)
  @connection = connection
end

Instance Method Details

#commitObject

Commits the transaction



26
27
# File 'lib/dbagile/core/transaction.rb', line 26

def commit
end

#execute(&block) ⇒ Object

Executes a block

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/dbagile/core/transaction.rb', line 18

def execute(&block)
  raise ArgumentError, "Missing transaction block" unless block
  connection.chain.transaction do
    block.call(self)
  end
end

#rollbackObject

Rollbacks the transaction



30
31
32
# File 'lib/dbagile/core/transaction.rb', line 30

def rollback
  raise DbAgile::AbordTransactionError
end

#transaction(&block) ⇒ Object

Executes the block inside this transaction



53
54
55
# File 'lib/dbagile/core/transaction.rb', line 53

def transaction(&block)
  execute(&block)
end