class ExceptionExtensions::ExceptionPathTraverser
Public Instance Methods
each(&block)
click to toggle source
# File lib/exception_extensions/exception_path_traverser.rb, line 3 def each(&block) if block_given? return if @exception.nil? each_internal(@exception, [], &block) else to_enum(:each) end end
Private Instance Methods
each_internal(exception, path, &block)
click to toggle source
# File lib/exception_extensions/exception_path_traverser.rb, line 14 def each_internal(exception, path, &block) # NOTE: path.clone is required because otherwise to_a will return empty array (since path will be an empty array after everything has executed) # NOTE: path.clone will clone the array, but not the exceptions, so duplicate exceptions will be the same object ID! return block.call(path.clone) if exception.nil? path.push(exception) if exception.respond_to?(:causes) exception.causes.each do |cause| each_internal(cause, path, &block) end else each_internal(exception.cause, path, &block) end path.pop end