Class: CallLogger::MethodWrapper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter:, logger:) ⇒ MethodWrapper

Returns a new instance of MethodWrapper.



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

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

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



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

def formatter
  @formatter
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

#call(method, args) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/call_logger/call_logger.rb', line 10

def call(method, args)
  logger.call(formatter.before(method, args))
  result = yield
  logger.call(formatter.after(method, result))
  result
rescue StandardError => e
  logger.call(formatter.error(method, e))
  raise
end