lib/enhanced/exception.rb in enhanced_errors-2.1.3 vs lib/enhanced/exception.rb in enhanced_errors-2.2.0

- old
+ new

@@ -1,8 +1,18 @@ # exception.rb +require_relative 'enhanced_exception_context' -class Exception +module ExceptionBindingInfos + def binding_infos + ctx = EnhancedExceptionContext.context_for(self) + unless ctx + ctx = Context.new + EnhancedExceptionContext.store_context(self, ctx) + end + ctx.binding_infos + end + def captured_variables if binding_infos.any? bindings_of_interest = select_binding_infos EnhancedErrors.format(bindings_of_interest) else @@ -10,14 +20,10 @@ end rescue '' end - def binding_infos - @binding_infos ||= [] - end - private def select_binding_infos # Preference: # 1. First 'raise' binding that isn't from a library (gem). @@ -40,6 +46,10 @@ end bindings_of_interest << last_rescue if last_rescue bindings_of_interest.compact end +end + +class Exception + prepend ExceptionBindingInfos end