exceptions_tree 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +9 -1
- data/exceptions_tree.gemspec +1 -0
- data/lib/exceptions_tree/display.rb +19 -9
- data/lib/exceptions_tree/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2dff87f3d8aefa0e89e9225f8e46dd994815ff
|
4
|
+
data.tar.gz: 652057ed0cc4d4ebb9f937563154472b66c1ba9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c544a6e05529022d187ac3b304b85966d4ef65ff6bf077f9b9720585f11542d861d245c2d686156720a315bcf50a54aded43ad94f5c2a2fe61d71f1ec3aef76
|
7
|
+
data.tar.gz: 436f0ce7b3a87df7db1f2e8997536a01e095730be7e6a32a8eb8d016fb2b665844b5ed5b0149330c6d3908868eb7e822e756123667260f6dbaf785f46b2ab15d
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/exceptions_tree.gemspec
CHANGED
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.13"
|
37
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
#spec.add_development_dependency "awesome_print" # debugging
|
38
39
|
#spec.add_development_dependency "pry-byebug" # only when debugging
|
39
40
|
end
|
@@ -1,25 +1,35 @@
|
|
1
1
|
module ExceptionsTree
|
2
2
|
|
3
3
|
class <<self
|
4
|
+
|
5
|
+
CLASSES_TO_IGNORE = [ Object, Kernel, BasicObject ]
|
6
|
+
|
4
7
|
def display_exceptions
|
8
|
+
puts inspect_exceptions_tree(build_exceptions_tree, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_exceptions_tree
|
5
12
|
exception_classes = []
|
6
|
-
|
13
|
+
exceptions_tree = {}
|
7
14
|
ObjectSpace.each_object(Class) do |klass|
|
8
|
-
next unless klass.ancestors.include?
|
9
|
-
next if exception_classes.include?
|
15
|
+
next unless klass.ancestors.include?(Exception)
|
16
|
+
next if exception_classes.include?(klass)
|
10
17
|
next if klass.superclass == SystemCallError # don't want ERRNO
|
18
|
+
next if CLASSES_TO_IGNORE.include?(klass)
|
11
19
|
exception_classes << klass
|
12
|
-
klass.ancestors.delete_if {|e|
|
13
|
-
reverse.inject(
|
20
|
+
klass.ancestors.delete_if {|e| CLASSES_TO_IGNORE.include?(e)}.
|
21
|
+
reverse.inject(exceptions_tree) {|memo,klass2| memo[klass2] ||= {}}
|
14
22
|
end
|
15
|
-
|
23
|
+
exceptions_tree
|
16
24
|
end
|
17
25
|
|
18
|
-
def
|
26
|
+
def inspect_exceptions_tree(tree, level)
|
27
|
+
output = ''
|
19
28
|
tree.keys.sort {|k1, k2| k1.name <=> k2.name}.each do |class_name|
|
20
|
-
|
21
|
-
|
29
|
+
output += sprintf("%s%s\n", (' ' * level), class_name)
|
30
|
+
output += inspect_exceptions_tree(tree[class_name], level+1)
|
22
31
|
end
|
32
|
+
output
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|