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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb18aab90a9fab876a96732f07b7a9115c745c15
4
- data.tar.gz: b151a192c5a71787246468fb7afd10f8dd847fea
3
+ metadata.gz: 2c2dff87f3d8aefa0e89e9225f8e46dd994815ff
4
+ data.tar.gz: 652057ed0cc4d4ebb9f937563154472b66c1ba9e
5
5
  SHA512:
6
- metadata.gz: dee5fe6aeb74ceb254c62e7c36e74fabe8842f87ede8be5efd60a41a8e9287fef6d80eeefad9b4860c440d7650d8783622cc3e4535f2ba9b4070fc3e219bb53c
7
- data.tar.gz: 65c56d21907248660c63a7438bd85ba0cc10c26afcca3358504b0e4c5a80194f68c53a89864cbc65d9dd375de6db23293c8cdde6cf397a43b42e84497167ad0c
6
+ metadata.gz: 1c544a6e05529022d187ac3b304b85966d4ef65ff6bf077f9b9720585f11542d861d245c2d686156720a315bcf50a54aded43ad94f5c2a2fe61d71f1ec3aef76
7
+ data.tar.gz: 436f0ce7b3a87df7db1f2e8997536a01e095730be7e6a32a8eb8d016fb2b665844b5ed5b0149330c6d3908868eb7e822e756123667260f6dbaf785f46b2ab15d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/test*.rb']
9
+ t.verbose = true
10
+ end
@@ -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
- exception_tree = {}
13
+ exceptions_tree = {}
7
14
  ObjectSpace.each_object(Class) do |klass|
8
- next unless klass.ancestors.include? Exception
9
- next if exception_classes.include? klass
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| [Object, Kernel].include? e }.
13
- reverse.inject(exception_tree) {|memo,klass2| memo[klass2] ||= {}}
20
+ klass.ancestors.delete_if {|e| CLASSES_TO_IGNORE.include?(e)}.
21
+ reverse.inject(exceptions_tree) {|memo,klass2| memo[klass2] ||= {}}
14
22
  end
15
- show_exception_tree(exception_tree, 0)
23
+ exceptions_tree
16
24
  end
17
25
 
18
- def show_exception_tree(tree, level)
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
- printf "%s%s\n", (' ' * level), class_name
21
- show_exception_tree(tree[class_name], level+1)
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
 
@@ -1,3 +1,3 @@
1
1
  module ExceptionsTree
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Stebbens