Class: TransactionLogger::TransactionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/transaction_logger/transaction_manager.rb

Constant Summary collapse

@@prefix =
""
@@current_transactions =
{}

Class Method Summary collapse

Class Method Details

.start(options = {}, lmbda) ⇒ Object

Marks the beginning of a "Transaction lambda," which will log an error if the containing code raises an error. A lambda instance variable let's you call the .log method and access the ".name" and ".context" variables. The start method must take a lambda as an argument.

Whatever the outer method is, if a value is returned within the Transaction lambda it will be returned to the outer method as well.

The start method does not catch errors, so if an error is raised, it will simply envoke a logging message to be outputted and then raise the error.

This also checks which thread is envoking the method in order to make sure the logs are thread-safe.

Parameters:

  • prefix (String)
  • logger (Logger)
  • level_threshold (Symbol)
  • lmbda (Proc)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/transaction_logger/transaction_manager.rb', line 30

def self.start(options={}, lmbda)
  options[:parent] = active_transaction

  transaction = TransactionLogger::Transaction.new options, lmbda
  self.active_transaction = transaction

  begin
    transaction.run
  rescue StandardError => e
    raise e
  ensure
    self.active_transaction = transaction.parent
  end
end