Exception: Exception
- Defined in:
- lib/exception_details/exception.rb
Overview
Extend the Ruby Exception class with our helper methods.
Constant Summary
Constants included from ExceptionDetails::InspectVariables
ExceptionDetails::InspectVariables::SCOPES
Instance Attribute Summary collapse
-
#binding_during_exception ⇒ Object
binding_during_exception lets you actually directly access the exception-time binding.
Class Method Summary collapse
- .__new__ ⇒ Object
- .inherited(subclass) ⇒ Object
-
.new(*args, &block) ⇒ Object
override the .new method on exception to grab the binding where the exception occurred.
Instance Method Summary collapse
-
#details(options = {}) ⇒ Object
.details provides a fairly complete string for logging purposes.
-
#inspect_variables(opts = {}) ⇒ Object
Provides a string with the variable names and values captured at exception time.
Methods included from ExceptionDetails::LogColorHelpers
#bg_black, #bg_blue, #bg_brown, #bg_cyan, #bg_gray, #bg_green, #bg_magenta, #bg_red, #black, #blue, #bold, #brown, #cyan, #gray, #green, #magenta, #red, #reverse_color
Instance Attribute Details
#binding_during_exception ⇒ Object
binding_during_exception lets you actually directly access the exception-time binding.
10 11 12 |
# File 'lib/exception_details/exception.rb', line 10 def binding_during_exception @binding_during_exception end |
Class Method Details
.__new__ ⇒ Object
37 |
# File 'lib/exception_details/exception.rb', line 37 alias :__new__ :new |
.inherited(subclass) ⇒ Object
39 40 41 42 43 |
# File 'lib/exception_details/exception.rb', line 39 def inherited(subclass) class << subclass alias :new :__new__ end end |
.new(*args, &block) ⇒ Object
override the .new method on exception to grab the binding where the exception occurred.
47 48 49 50 51 |
# File 'lib/exception_details/exception.rb', line 47 def self.new(*args, &block) e = __new__(*args) e.binding_during_exception = binding.of_caller(1) e end |
Instance Method Details
#details(options = {}) ⇒ Object
.details provides a fairly complete string for logging purposes. The message, variables in the exception’s scope, and their current values are outputted, followed by the whole backtrace.
-
options
- options default: [:local_variables, :instance_variables, :class_variables]
- options[:colorize] true / false. Whether to add color to the output (for terminal/log)
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/exception_details/exception.rb', line 23 def details( = {}) = {colorize: true}.merge() inspect_results = inspect_variables() parts = [] parts << ([:colorize] ? red('Exception:') : 'Exception:') parts << "\t" + "#{self.class.name}: #{}" parts << ([:colorize] ? red('Variables:') : 'Variables:') parts << inspect_results parts << ([:colorize] ? red('Backtrace:') : 'Backtrace:') parts << "\t" + backtrace.to_a.join("\n") parts.join("\n") end |
#inspect_variables(opts = {}) ⇒ Object
Provides a string with the variable names and values captured at exception time.
14 15 16 |
# File 'lib/exception_details/exception.rb', line 14 def inspect_variables(opts = {}) variable_inspect_string(binding_during_exception, opts) end |