format_exception 0.2.2 → 0.3.0

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: 4548192228f4401a9406cda8cad72e9e9199274e
4
- data.tar.gz: 64e00e6ec34e825f4807f8723810fb976c7f5c4e
3
+ metadata.gz: ffe2b381b1536f380b63639ec159f1464dd17b74
4
+ data.tar.gz: 465db21e56eb05d16147b8f55aff078850821b0d
5
5
  SHA512:
6
- metadata.gz: e75be10a7baf9635c90801f8e81c5e7957e93cf3f1a852799501e8ca7202f45e0d5467002f312d4e6eba1e89c3675ebea43d52b7a20cc0013008ca5e4a1d0569
7
- data.tar.gz: 206542474ae658cf3039c82758ad579d4dc67bea91935b66beb5fe66d5f5837685c4018574228ed78de8a798091a38a1282f830d00190c100b0fb7b1d8476434
6
+ metadata.gz: 6855f0be228cc57688decd3d9ccb4c74e8687d26c42eac23cedc772c4570552dff449cde14fbba05cfbea252befc4f5bbb9b0012e92d1c491b73883b2a55a69f
7
+ data.tar.gz: b3beeb426b4cd48d962de0bf441a7d11d60d4f087545048ce0dda33494c0b98d272dbd80a44dbc8eecd170c26803dd90b91f52f7a7d6d2b7eca57125cbef1e2b
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
+ [![Gem Version](https://badge.fury.io/rb/format_exception.svg)](http://badge.fury.io/rb/format_exception) [![Build Status](https://travis-ci.org/hetznerZA/format_exception.svg?branch=master)](https://travis-ci.org/hetznerZA/format_exception)
2
+
1
3
  # FormatException
2
4
 
3
5
  A module of utility methods for string formatting exceptions.
4
6
 
5
7
  ## Documentation
6
8
 
7
- For documentation of the released gem, see [rubydoc.info](http://www.rubydoc.info/gems/format_exception).
9
+ For documentation, follow the _Documentation_ link of the released gem on [rubygems.org](https://rubygems.org/gems/format_exception).
8
10
 
9
11
  ## Installation
10
12
 
@@ -6,7 +6,26 @@ require "strscan"
6
6
  #
7
7
  # Provides utility methods for formatting an exception as a String.
8
8
  #
9
- # @example The contextual clean format
9
+ # @example Classic format
10
+ #
11
+ # require "format_exception"
12
+ #
13
+ # def make_mistake
14
+ # begin
15
+ # raise "Deliberate mistake"
16
+ # rescue Exception => ex
17
+ # $stderr.puts FormatException.classic(ex)
18
+ # end
19
+ # end
20
+ #
21
+ # make_mistake
22
+ #
23
+ # # Prints:
24
+ # #
25
+ # # example.rb:7:in `make_mistake': Deliberate mistake (RuntimeError)
26
+ # # example.rb:13:in `<main>'
27
+ #
28
+ # @example Contextual clean format to Logger
10
29
  #
11
30
  # require "logger"
12
31
  # require "format_exception"
@@ -16,7 +35,7 @@ require "strscan"
16
35
  # File.open("message.txt", "r") do |io|
17
36
  # puts io.read
18
37
  # end
19
- # rescue IOError => ex
38
+ # rescue StandardError => ex
20
39
  # logger.error(FormatException[ex, "Printing welcome message"])
21
40
  # end
22
41
  #
@@ -27,6 +46,43 @@ require "strscan"
27
46
  # # foo.rb:10:in `open'
28
47
  # # foo.rb:10:in `<main>'
29
48
  #
49
+ # @example Contextual custom format
50
+ #
51
+ # require "format_exception"
52
+ #
53
+ # def make_mistake
54
+ # begin
55
+ # raise "Deliberate mistake"
56
+ # rescue Exception => ex
57
+ # $stderr.puts FormatException.format("%:m%C(\"%M\") at %f\n%R", ex, "Testing formatter")
58
+ # end
59
+ # end
60
+ #
61
+ # make_mistake
62
+ #
63
+ # # Prints
64
+ # #
65
+ # # Testing formatter: RuntimeError("Deliberate mistake") at example.rb:7:in `make_mistake'
66
+ # # example.rb:13:in `<main>'
67
+ #
68
+ # @example Data format
69
+ #
70
+ # require "format_exception"
71
+ #
72
+ # def make_mistake
73
+ # begin
74
+ # raise "Deliberate mistake"
75
+ # rescue Exception => ex
76
+ # $stderr.puts FormatException.classic(ex).to_s
77
+ # end
78
+ # end
79
+ #
80
+ # make_mistake
81
+ #
82
+ # # Prints:
83
+ # #
84
+ # # {:name=>"RuntimeError", :message=>"Deliberate mistake", :backtrace=>["(irb):19:in `make_mistake'", ...]}
85
+ #
30
86
  module FormatException
31
87
 
32
88
  ##
@@ -85,6 +141,31 @@ module FormatException
85
141
  format(CLEAN_FORMAT, e, context_message)
86
142
  end
87
143
 
144
+ ##
145
+ # Format exception as symbol-keyed dictionary
146
+ #
147
+ # If the +context_message+ is given, it is included as the +:context_message+ key.
148
+ #
149
+ # @param [Exception] e
150
+ # the exception to format
151
+ # @param [String] context_message
152
+ # the additional message to include in the dictionary
153
+ # @return [Hash] the data representation of the exception
154
+ # * +:name+ (String) exception class name
155
+ # * +:message+ (String) exception message
156
+ # * +:backtrace+ (Array) exception backtrace
157
+ # * +:context_message+ (String) +context_message+ if specified
158
+ #
159
+ def self.data(e, context_message = nil)
160
+ {
161
+ name: e.class.to_s,
162
+ message: e.message,
163
+ backtrace: e.backtrace,
164
+ }.tap { |h|
165
+ h[:context_message] = context_message if context_message
166
+ }
167
+ end
168
+
88
169
  ##
89
170
  # Format exception as per printf-like format specifier
90
171
  #
@@ -126,4 +207,5 @@ module FormatException
126
207
  end
127
208
  formatted
128
209
  end
210
+
129
211
  end
@@ -1,3 +1,3 @@
1
1
  module FormatException
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_exception
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-11 00:00:00.000000000 Z
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.5.1
94
+ rubygems_version: 2.5.2.1
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Exception formatter
98
98
  test_files: []
99
- has_rdoc: