pretty_trace 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d8187f1a160dfa57ad3431758d0ef5a5db5e579
4
- data.tar.gz: e5523337c8797d52d4f8e2b698afcfd35ee33f91
3
+ metadata.gz: 579685ff281ef135925131b6f4e3c08a8e5d9072
4
+ data.tar.gz: 75179399e4b8548338bfe95ca77392374bae5397
5
5
  SHA512:
6
- metadata.gz: b6e4ae015526639834b3a5b9872241ae65b7d3614a890f3f715a52071e6001b30cc44ad1b1b57ab148b7534c188de4e9ee4f198d88013c0cc1c96e613a78c4fc
7
- data.tar.gz: 0fd788761adcb08c129d9c606ed94d9c5e0582ce9056b31e3e6bfa9c459a119cb230bf5485f6868103e030f2479f1540ff34c5ee15b37839b884a3ce2e8bee43
6
+ metadata.gz: ef62bb07f161ce52abc03b6f68ee7ae08de4c8306aba1a5c2562cfdcac5f9494aeb7ccad487201cd8e5826fa94477cb1c3de7ec57898fa0a1a9436597ba71c05
7
+ data.tar.gz: 8aa643e2e3380994e7c759d6271e3d8244e1f5134f9ae2303a35568d3a56c55dd1249bbd19595c60594c7f08e80d4ec4026967aa15afa68018dacd869d83aab5
data/README.md CHANGED
@@ -1,17 +1,35 @@
1
1
  Pretty Trace - Pretty Errors and Backtrace
2
2
  ==================================================
3
3
 
4
- This forces any of your Ruby scripts to show a pretty backtrace.
4
+ [![Gem](https://img.shields.io/gem/v/pretty_trace.svg?style=flat-square)](https://rubygems.org/gems/pretty_trace)
5
+ [![Travis](https://img.shields.io/travis/DannyBen/pretty_trace.svg?style=flat-square)](https://travis-ci.org/DannyBen/pretty_trace)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/pretty_trace.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/pretty_trace)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/pretty_trace.svg?style=flat-square)](https://gemnasium.com/DannyBen/pretty_trace)
8
+
9
+ ---
10
+
11
+ Make your Ruby backtrace pretty again. Just require `pretty_trace/enable`
12
+ in your ruby script, and errors will become clearer and more readable.
13
+
14
+ ---
5
15
 
6
16
  Install
7
17
  --------------------------------------------------
8
18
 
9
- $ gem install pretty_trace
19
+ ```
20
+ $ gem install pretty_trace
21
+ ```
22
+
23
+ Or with bundler:
24
+
25
+ ```
26
+ $ gem 'pretty_trace', require: 'pretty_trace/enable'
27
+ ```
10
28
 
11
29
  Example
12
30
  --------------------------------------------------
13
31
 
14
- 1. Create this ruby file:
32
+ ### Create this ruby file:
15
33
 
16
34
  ```ruby
17
35
  # test.rb
@@ -20,15 +38,60 @@ require "fileutils"
20
38
  FileUtils.rm 'no_such_file'
21
39
  ```
22
40
 
23
- 2. Run it:
41
+ ### Run it:
24
42
 
25
- $ ruby test.rb
43
+ ![screenshot](/screenshot.png)
26
44
 
27
- 3. Get a pretty exception
28
45
 
29
- ![screenshot](/screenshot.png)
46
+ Usage
47
+ --------------------------------------------------
48
+
49
+ The easiest way to use Pretty Trace is to require its activation script in
50
+ your script:
30
51
 
52
+ ```ruby
53
+ require 'pretty_trace/enable'
54
+ ```
31
55
 
56
+ From this point on, any exception will be formatted.
32
57
 
58
+ If you prefer to enable/disable the formatted backtrace manually, use
59
+ `PrettyTrace.enable` and `PrettyTrace.disable`
60
+
61
+ ```ruby
62
+ require 'pretty_trace'
33
63
 
64
+ # Exceptions here will not be formatted
34
65
 
66
+ PrettyTrace.enable
67
+
68
+ # Exceptions here will be formatted
69
+
70
+ PrettyTrace.disable
71
+
72
+ # Exceptions here will not be formatted
73
+ ```
74
+
75
+
76
+ Configuration
77
+ --------------------------------------------------
78
+
79
+ To filter out lines in the backtrace, use `PrettyTrace.filter`. This method
80
+ accepts a single regular expression, or an array of regular expressions.
81
+
82
+ Note that you can call this method several times, and it will aggregate all
83
+ your filters together.
84
+
85
+ ```ruby
86
+ require 'pretty_trace/enable'
87
+ PrettyTrace.filter /rails/
88
+ PrettyTrace.filter [/gem/, /lib/]
89
+ ```
90
+
91
+ If you wish to temporarily disable Pretty Trace (for example, when you need
92
+ to see the full trace paths), you can set the environment variable
93
+ `PRETTY_TRACE=off` before running your script:
94
+
95
+ ```
96
+ $ PRETTY_TRACE=off ruby myscript.rb
97
+ ```
@@ -1,5 +1,3 @@
1
- require 'ostruct'
2
-
3
1
  module PrettyTrace
4
2
  class Formatter
5
3
  def self.pretty_trace(backtrace, opts={})
@@ -11,12 +9,12 @@ module PrettyTrace
11
9
  end
12
10
 
13
11
  backtrace.map! do |item|
14
- if item =~ /(.+):(\d+):in `(.+)'/
12
+ if item =~ /(.+):(-?\d+):in `(.+)'/
15
13
  file, line, method = $1, $2, $3
16
14
  dir = File.dirname(file).split('/').last
17
15
  dir = dir == '.' ? '' : "#{dir}/"
18
-
19
16
  file = File.basename file
17
+
20
18
  item = "line %{green}#{line.to_s.ljust 4}%{reset} in %{cyan}#{dir}%{magenta}#{file}%{reset} > %{blue}#{method}%{reset}" % colors
21
19
  end
22
20
  item
@@ -25,8 +23,6 @@ module PrettyTrace
25
23
  backtrace
26
24
  end
27
25
 
28
- private
29
-
30
26
  def self.colors
31
27
  {
32
28
  reset: "\e[0m",
@@ -41,4 +37,4 @@ module PrettyTrace
41
37
  }
42
38
  end
43
39
  end
44
- end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module PrettyTrace
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-16 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runfile