Class: TransactionLogger::Transaction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, lmbda) ⇒ Transaction

Returns a new instance of Transaction.

Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/transaction_logger/transaction.rb', line 11

def initialize(parent=nil, lmbda)
  @parent = parent
  @parent.log self if @parent

  @lmbda = lmbda

  @name = "undefined"
  @context = {}
  @log_queue = Array.new
  @start = Time.now
  @error_printed = nil
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/transaction_logger/transaction.rb', line 6

def context
  @context
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/transaction_logger/transaction.rb', line 5

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



3
4
5
# File 'lib/transaction_logger/transaction.rb', line 3

def parent
  @parent
end

Instance Method Details

#log(message) ⇒ Object

Pushes a message into the log queue. Logs are stored in order of time logged. Note that this method will not output a log, but just stores it in the queue to be outputted if an error is raised in a transaction.

Parameters:

  • message (#to_s)

    Any String or Object that responds to to_s that you want to be stored in the log queue.



58
59
60
61
62
63
64
65
66
# File 'lib/transaction_logger/transaction.rb', line 58

def log(message)
  if message.is_a? String
    message_key = "#{TransactionLogger.log_prefix}info"
    message = { message_key => message }
    @log_queue.push message
  else
    @log_queue.push message
  end
end