Class: CallLogger::CallWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/call_logger/call_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter:, logger:) ⇒ CallWrapper

Returns a new instance of CallWrapper.



7
8
9
10
# File 'lib/call_logger/call_wrapper.rb', line 7

def initialize(formatter:, logger: )
  @formatter = formatter
  @logger = logger
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



5
6
7
# File 'lib/call_logger/call_wrapper.rb', line 5

def formatter
  @formatter
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/call_logger/call_wrapper.rb', line 5

def logger
  @logger
end

Instance Method Details

#call(name, args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/call_logger/call_wrapper.rb', line 12

def call(name, args)
  logger.call(formatter.before(name, args))
  result = nil
  seconds = Benchmark.realtime { result = yield }
  logger.call(formatter.after(name, result, seconds: seconds))
  result
rescue StandardError => e
  logger.call(formatter.error(name, e))
  raise
end