pretty_trace 0.1.0 → 0.1.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: 579685ff281ef135925131b6f4e3c08a8e5d9072
4
- data.tar.gz: 75179399e4b8548338bfe95ca77392374bae5397
3
+ metadata.gz: 01f4109d20baa996682e6f71ce0ea1b03d7d95ac
4
+ data.tar.gz: ecb6f5346c533dc4915df2abe151c098423627da
5
5
  SHA512:
6
- metadata.gz: ef62bb07f161ce52abc03b6f68ee7ae08de4c8306aba1a5c2562cfdcac5f9494aeb7ccad487201cd8e5826fa94477cb1c3de7ec57898fa0a1a9436597ba71c05
7
- data.tar.gz: 8aa643e2e3380994e7c759d6271e3d8244e1f5134f9ae2303a35568d3a56c55dd1249bbd19595c60594c7f08e80d4ec4026967aa15afa68018dacd869d83aab5
6
+ metadata.gz: 0a4c2476428a4a7e4a29d6fcc183c0159fe5b51aed461a15a207394b6fac1cad2124a648be183e24fb4dd819272c7a8cd988e3ae63d945cc943a8d2cc10e88b4
7
+ data.tar.gz: cb7c2888add66b808803af25b5b52c5ee37e51a87149df709757c5e90c56e204c302c64cea6a55ee18d1cb334e6802c417c04446f0a758b962954aaa0f08b979
data/README.md CHANGED
@@ -23,7 +23,14 @@ $ gem install pretty_trace
23
23
  Or with bundler:
24
24
 
25
25
  ```
26
+ # Just install, do not activate
27
+ $ gem 'pretty_trace'
28
+
29
+ # Install and enable
26
30
  $ gem 'pretty_trace', require: 'pretty_trace/enable'
31
+
32
+ # Install, enable and enable trimming
33
+ $ gem 'pretty_trace', require: 'pretty_trace/enable-trim'
27
34
  ```
28
35
 
29
36
  Example
@@ -55,8 +62,15 @@ require 'pretty_trace/enable'
55
62
 
56
63
  From this point on, any exception will be formatted.
57
64
 
58
- If you prefer to enable/disable the formatted backtrace manually, use
59
- `PrettyTrace.enable` and `PrettyTrace.disable`
65
+ If you wish to show a trimmed version of the backtrace (only the first and
66
+ last line), require this script instead:
67
+
68
+ ```ruby
69
+ require 'pretty_trace/enable-trim'
70
+ ```
71
+
72
+ If you prefer to have more control,you can use configure these settings
73
+ manually:
60
74
 
61
75
  ```ruby
62
76
  require 'pretty_trace'
@@ -70,6 +84,14 @@ PrettyTrace.enable
70
84
  PrettyTrace.disable
71
85
 
72
86
  # Exceptions here will not be formatted
87
+
88
+ PrettyTrace.trim
89
+
90
+ # Exceptions here will be trimmed
91
+
92
+ PrettyTrace.no_trim
93
+
94
+ # Exceptions here will not be trimmed
73
95
  ```
74
96
 
75
97
 
@@ -95,3 +117,11 @@ to see the full trace paths), you can set the environment variable
95
117
  ```
96
118
  $ PRETTY_TRACE=off ruby myscript.rb
97
119
  ```
120
+
121
+ If you wish to temporarily disable trimming, you can set the environment
122
+ variable `PRETTY_TRACE=full` before running your script:
123
+
124
+ ```
125
+ $ PRETTY_TRACE=full ruby myscript.rb
126
+ ```
127
+
@@ -0,0 +1,3 @@
1
+ require 'pretty_trace'
2
+ PrettyTrace.enable
3
+ PrettyTrace.trim
@@ -8,6 +8,8 @@ module PrettyTrace
8
8
  backtrace.reject! { |trace| trace =~ expression }
9
9
  end
10
10
 
11
+ backtrace = trim backtrace if should_trim? backtrace
12
+
11
13
  backtrace.map! do |item|
12
14
  if item =~ /(.+):(-?\d+):in `(.+)'/
13
15
  file, line, method = $1, $2, $3
@@ -36,5 +38,14 @@ module PrettyTrace
36
38
  white: "\e[37m",
37
39
  }
38
40
  end
41
+
42
+ def self.trim(backtrace)
43
+ [backtrace[0], '...... (trimmed)', backtrace[-1]]
44
+ end
45
+
46
+ def self.should_trim?(backtrace)
47
+ ENV['PRETTY_TRACE_TRIM'] and ENV['PRETTY_TRACE'] != 'full' and
48
+ backtrace.size > 3
49
+ end
39
50
  end
40
51
  end
@@ -31,4 +31,4 @@ module PrettyTrace
31
31
  { filter: [] }
32
32
  end
33
33
  end
34
- end
34
+ end;
@@ -14,4 +14,12 @@ module PrettyTrace
14
14
  Handler.instance.options[:filter] << filter
15
15
  end
16
16
  end
17
+
18
+ def self.trim
19
+ ENV['PRETTY_TRACE_TRIM'] = '1'
20
+ end
21
+
22
+ def self.no_trim
23
+ ENV['PRETTY_TRACE_TRIM'] = nil
24
+ end
17
25
  end
@@ -1,3 +1,3 @@
1
1
  module PrettyTrace
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.1.0
4
+ version: 0.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runfile
@@ -88,6 +88,7 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - README.md
90
90
  - lib/pretty_trace.rb
91
+ - lib/pretty_trace/enable-trim.rb
91
92
  - lib/pretty_trace/enable.rb
92
93
  - lib/pretty_trace/formatter.rb
93
94
  - lib/pretty_trace/handler.rb