Class: CallLogger::CallWrapper
- Inherits:
-
Object
- Object
- CallLogger::CallWrapper
- Defined in:
- lib/call_logger/call_wrapper.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #call(name, args) ⇒ Object
-
#initialize(formatter:, logger:) ⇒ CallWrapper
constructor
A new instance of CallWrapper.
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
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
5 6 7 |
# File 'lib/call_logger/call_wrapper.rb', line 5 def formatter @formatter end |
#logger ⇒ Object (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 |