class TransactionLogger::Helper

Public Class Methods

trap_logger(_method, transaction, method_info={}) click to toggle source

@private Traps the original logger inside the TransactionLogger

@param method [Symbol] @param transaction [Transaction]

# File lib/transaction_logger.rb, line 86
def self.trap_logger(_method, transaction, method_info={})
  logger_method = method_info[:logger_method]
  calling_method = method_info[:calling_method]
  includer = method_info[:includer]

  if logger_method.is_a? UnboundMethod
    method_type = :define_method
  else
    method_type = :define_singleton_method
  end

  includer.class.send method_type, :logger, lambda {
    if logger_method.is_a? UnboundMethod
      @original_logger ||= logger_method.bind(includer).call
    else
      @original_logger ||= logger_method.call
    end

    @trapped_logger ||= {}
    @trapped_logger[calling_method] ||= LoggerProxy.new @original_logger, transaction
  }
end