Exception: Exception
- Defined in:
- lib/exception_details/exception.rb
Overview
Extend the Ruby Exception class with our helper methods.
Constant Summary collapse
- @@filter_variables =
[]
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
- .filter_variables ⇒ Object
-
.filter_variables=(variable_names_to_filter) ⇒ Object
Filtered items will show up with variable values like ‘FILTERED’.
- .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.
30 31 32 |
# File 'lib/exception_details/exception.rb', line 30 def binding_during_exception @binding_during_exception end |
Class Method Details
.__new__ ⇒ Object
57 |
# File 'lib/exception_details/exception.rb', line 57 alias :__new__ :new |
.filter_variables ⇒ Object
24 25 26 |
# File 'lib/exception_details/exception.rb', line 24 def self.filter_variables @@filter_variables end |
.filter_variables=(variable_names_to_filter) ⇒ Object
Filtered items will show up with variable values like ‘FILTERED’
19 20 21 22 |
# File 'lib/exception_details/exception.rb', line 19 def self.filter_variables=(variable_names_to_filter) variable_names_to_filter = variable_names_to_filter.map {|v| v.to_s} @@filter_variables = variable_names_to_filter end |
.inherited(subclass) ⇒ Object
59 60 61 62 63 |
# File 'lib/exception_details/exception.rb', line 59 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.
67 68 69 70 71 |
# File 'lib/exception_details/exception.rb', line 67 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)
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/exception_details/exception.rb', line 43 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.
34 35 36 |
# File 'lib/exception_details/exception.rb', line 34 def inspect_variables(opts = {}) variable_inspect_string(binding_during_exception, opts) end |