Module: ExceptionsTree

Defined in:
lib/exceptions_tree/display.rb,
lib/exceptions_tree/railtie.rb,
lib/exceptions_tree/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

CLASSES_TO_IGNORE =
[ Object, Kernel, BasicObject ]
VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.build_exceptions_treeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/exceptions_tree/display.rb', line 11

def build_exceptions_tree
  exception_classes = []
  exceptions_tree = {}
  ObjectSpace.each_object(Class) do |klass|
    next unless klass.ancestors.include?(Exception)
    next if exception_classes.include?(klass)
    next if klass.superclass == SystemCallError # don't want ERRNO
    next if CLASSES_TO_IGNORE.include?(klass)
    exception_classes << klass
    klass.ancestors.delete_if {|e| CLASSES_TO_IGNORE.include?(e)}.
        reverse.inject(exceptions_tree) {|memo,klass2| memo[klass2] ||= {}}
  end
  exceptions_tree
end

.display_exceptionsObject



7
8
9
# File 'lib/exceptions_tree/display.rb', line 7

def display_exceptions
  puts inspect_exceptions_tree(build_exceptions_tree, 0)
end

.inspect_exceptions_tree(tree, level) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/exceptions_tree/display.rb', line 26

def inspect_exceptions_tree(tree, level)
  output = ''
  tree.keys.sort {|k1, k2| k1.name <=> k2.name}.each do |class_name|
    output += sprintf("%s%s\n", ('  ' * level), class_name)
    output += inspect_exceptions_tree(tree[class_name], level+1)
  end
  output
end