pretty_trace 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d8187f1a160dfa57ad3431758d0ef5a5db5e579
4
+ data.tar.gz: e5523337c8797d52d4f8e2b698afcfd35ee33f91
5
+ SHA512:
6
+ metadata.gz: b6e4ae015526639834b3a5b9872241ae65b7d3614a890f3f715a52071e6001b30cc44ad1b1b57ab148b7534c188de4e9ee4f198d88013c0cc1c96e613a78c4fc
7
+ data.tar.gz: 0fd788761adcb08c129d9c606ed94d9c5e0582ce9056b31e3e6bfa9c459a119cb230bf5485f6868103e030f2479f1540ff34c5ee15b37839b884a3ce2e8bee43
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ Pretty Trace - Pretty Errors and Backtrace
2
+ ==================================================
3
+
4
+ This forces any of your Ruby scripts to show a pretty backtrace.
5
+
6
+ Install
7
+ --------------------------------------------------
8
+
9
+ $ gem install pretty_trace
10
+
11
+ Example
12
+ --------------------------------------------------
13
+
14
+ 1. Create this ruby file:
15
+
16
+ ```ruby
17
+ # test.rb
18
+ require "pretty_trace/enable"
19
+ require "fileutils"
20
+ FileUtils.rm 'no_such_file'
21
+ ```
22
+
23
+ 2. Run it:
24
+
25
+ $ ruby test.rb
26
+
27
+ 3. Get a pretty exception
28
+
29
+ ![screenshot](/screenshot.png)
30
+
31
+
32
+
33
+
34
+
@@ -0,0 +1,2 @@
1
+ require 'pretty_trace'
2
+ PrettyTrace.enable
@@ -0,0 +1,44 @@
1
+ require 'ostruct'
2
+
3
+ module PrettyTrace
4
+ class Formatter
5
+ def self.pretty_trace(backtrace, opts={})
6
+ filter = opts[:filter] || []
7
+ filter = [filter] unless filter.is_a? Array
8
+
9
+ filter.each do |expression|
10
+ backtrace.reject! { |trace| trace =~ expression }
11
+ end
12
+
13
+ backtrace.map! do |item|
14
+ if item =~ /(.+):(\d+):in `(.+)'/
15
+ file, line, method = $1, $2, $3
16
+ dir = File.dirname(file).split('/').last
17
+ dir = dir == '.' ? '' : "#{dir}/"
18
+
19
+ file = File.basename file
20
+ item = "line %{green}#{line.to_s.ljust 4}%{reset} in %{cyan}#{dir}%{magenta}#{file}%{reset} > %{blue}#{method}%{reset}" % colors
21
+ end
22
+ item
23
+ end
24
+
25
+ backtrace
26
+ end
27
+
28
+ private
29
+
30
+ def self.colors
31
+ {
32
+ reset: "\e[0m",
33
+ black: "\e[30m",
34
+ red: "\e[31m",
35
+ green: "\e[32m",
36
+ yellow: "\e[33m",
37
+ blue: "\e[34m",
38
+ magenta:"\e[35m",
39
+ cyan: "\e[36m",
40
+ white: "\e[37m",
41
+ }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ require 'singleton'
2
+
3
+ module PrettyTrace
4
+ class Handler
5
+ include Singleton
6
+
7
+ def trace_point
8
+ @trace_point ||= trace_point!
9
+ end
10
+
11
+ def options
12
+ @options ||= default_options
13
+ end
14
+
15
+ def options=(new_options)
16
+ @options = new_options
17
+ end
18
+
19
+ private
20
+
21
+ def trace_point!
22
+ TracePoint.new :raise do |tp|
23
+ exception = tp.raised_exception
24
+ backtrace = exception.backtrace
25
+ pretty_trace = Formatter.pretty_trace backtrace, options
26
+ exception.set_backtrace pretty_trace
27
+ end
28
+ end
29
+
30
+ def default_options
31
+ { filter: [] }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ module PrettyTrace
2
+ def self.enable
3
+ Handler.instance.trace_point.enable unless ENV['PRETTY_TRACE'] == 'off'
4
+ end
5
+
6
+ def self.disable
7
+ Handler.instance.trace_point.disable
8
+ end
9
+
10
+ def self.filter(filter)
11
+ if filter.is_a? Array
12
+ Handler.instance.options[:filter] += filter
13
+ else
14
+ Handler.instance.options[:filter] << filter
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module PrettyTrace
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'pretty_trace/version'
2
+ require 'pretty_trace/handler'
3
+ require 'pretty_trace/formatter'
4
+ require 'pretty_trace/module_methods'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_trace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: runfile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: runfile-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
83
+ description: Display clean and colorful error messages and backtrace
84
+ email: db@dannyben.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - README.md
90
+ - lib/pretty_trace.rb
91
+ - lib/pretty_trace/enable.rb
92
+ - lib/pretty_trace/formatter.rb
93
+ - lib/pretty_trace/handler.rb
94
+ - lib/pretty_trace/module_methods.rb
95
+ - lib/pretty_trace/version.rb
96
+ homepage: https://github.com/DannyBen/pretty_trace
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.0.0
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.13
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Pretty backtrace and error messages
120
+ test_files: []