class Exception
Extend the Ruby Exception
class with our helper methods.
Attributes
binding_during_exception[RW]
binding_during_exception
lets you actually directly access the exception-time binding.
Public Class Methods
filter_variables()
click to toggle source
# File lib/exception_details/exception.rb, line 24 def self.filter_variables @@filter_variables end
filter_variables=(variable_names_to_filter)
click to toggle source
Filtered items will show up with variable values like ‘FILTERED’
# 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)
click to toggle source
# File lib/exception_details/exception.rb, line 59 def inherited(subclass) class << subclass alias :new :__new__ end end
new(*args, &block)
click to toggle source
override the .new method on exception to grab the binding where the exception occurred.
# 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
Also aliased as: __new__
Public Instance Methods
details(options = {})
click to toggle source
.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)
# File lib/exception_details/exception.rb, line 43 def details(options = {}) options = {colorize: true}.merge(options) inspect_results = inspect_variables(options) parts = [] parts << (options[:colorize] ? red('Exception:') : 'Exception:') parts << "\t" + "#{self.class.name}: #{message}" parts << (options[:colorize] ? red('Variables:') : 'Variables:') parts << inspect_results parts << (options[:colorize] ? red('Backtrace:') : 'Backtrace:') parts << "\t" + backtrace.to_a.join("\n") parts.join("\n") end
inspect_variables(opts = {})
click to toggle source
Provides a string with the variable names and values captured at exception time.
# File lib/exception_details/exception.rb, line 34 def inspect_variables(opts = {}) variable_inspect_string(binding_during_exception, opts) end