xqsr3 0.38.2 → 0.39.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +12 -12
- data/examples/count_word_frequencies.rb +4 -4
- data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +399 -399
- data/lib/xqsr3/containers/multi_map.rb +448 -448
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +51 -51
- data/lib/xqsr3/conversion/integer_parser.rb +87 -87
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
- data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +130 -130
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
- data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
- data/lib/xqsr3/extensions/hash/except.rb +16 -16
- data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
- data/lib/xqsr3/extensions/hash/match.rb +10 -10
- data/lib/xqsr3/extensions/hash/slice.rb +11 -11
- data/lib/xqsr3/extensions/hash.rb +1 -1
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
- data/lib/xqsr3/extensions/integer.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +28 -28
- data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
- data/lib/xqsr3/extensions/kernel.rb +1 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
- data/lib/xqsr3/extensions/string/map_option_string.rb +4 -4
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -1
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -1
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
- data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
- data/lib/xqsr3/io/writelines.rb +122 -120
- data/lib/xqsr3/quality/parameter_checking.rb +445 -445
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
- data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
- data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
- data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
- data/lib/xqsr3/string_utilities/truncate.rb +55 -55
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +12 -12
- data/test/performance/frequency_map.rb +12 -12
- data/test/scratch/test_assert_raise_with_message.rb +11 -11
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +591 -591
- data/test/unit/containers/tc_multi_map.rb +558 -558
- data/test/unit/conversion/tc_integer_parser.rb +72 -72
- data/test/unit/conversion/tc_to_bool.rb +25 -25
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
- data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
- data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
- data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
- data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
- data/test/unit/extensions/hash/tc_except.rb +28 -28
- data/test/unit/extensions/hash/tc_slice.rb +13 -13
- data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
- data/test/unit/extensions/integer/ts_all.rb +12 -0
- data/test/unit/extensions/io/tc_writelines.rb +149 -77
- data/test/unit/extensions/kernel/tc_integer.rb +75 -75
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
- data/test/unit/extensions/object/tc_inspect.rb +50 -50
- data/test/unit/extensions/string/tc_bool.tb +24 -24
- data/test/unit/extensions/string/tc_ends_with.rb +53 -53
- data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
- data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
- data/test/unit/extensions/string/tc_quote_if.rb +18 -18
- data/test/unit/extensions/string/tc_starts_with.rb +53 -53
- data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
- data/test/unit/extensions/string/tc_truncate.rb +18 -18
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
- data/test/unit/hash_utilities/tc_has_match.rb +70 -70
- data/test/unit/hash_utilities/tc_match.rb +83 -83
- data/test/unit/io/tc_writelines.rb +166 -106
- data/test/unit/quality/tc_parameter_checking.rb +389 -389
- data/test/unit/string_utilities/tc_truncate.rb +27 -27
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Definition of the ExceptionUtilities module
|
6
6
|
#
|
7
7
|
# Created: 12th February 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2019-
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -56,161 +56,161 @@ module Diagnostics
|
|
56
56
|
|
57
57
|
module ExceptionUtilities
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
59
|
+
# Raises an instance of a named exception that takes options in its
|
60
|
+
# constructor, as in:
|
61
|
+
#
|
62
|
+
# class ArgumentErrorWithOptions < ArgumentError
|
63
|
+
#
|
64
|
+
# def initialize(message = nil, **options)
|
65
|
+
#
|
66
|
+
# . . .
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# attr_reader :options
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# begin
|
73
|
+
#
|
74
|
+
# raise_with_options ArgumentErrorWithOptions, "message-1", opt1: :val1, opt2: 'val2'
|
75
|
+
# rescue => x
|
76
|
+
#
|
77
|
+
# $stderr.puts x.options # => {:opt1=>:val1, :opt2=>"val2"}
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# It can also be used with full compatibility with <tt>Kernel#raise</tt>, as in:
|
81
|
+
#
|
82
|
+
# begin
|
83
|
+
#
|
84
|
+
# raise_with_options ArgumentError, "message-2"
|
85
|
+
# rescue => x
|
86
|
+
#
|
87
|
+
# $stderr.puts x.class # => ArgumenError
|
88
|
+
# $stderr.puts x.message # => "message-2"
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# and:
|
92
|
+
#
|
93
|
+
# begin
|
94
|
+
#
|
95
|
+
# raise_with_options "message-3"
|
96
|
+
# rescue => x
|
97
|
+
#
|
98
|
+
# $stderr.puts x.class # => RuntimeError
|
99
|
+
# $stderr.puts x.message # => "message-3"
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# === Parameters
|
103
|
+
#
|
104
|
+
# * +args+ 0 or more arguments
|
105
|
+
# * +options+ An options hash
|
106
|
+
#
|
107
|
+
# === Parameter Interpretation
|
108
|
+
#
|
109
|
+
# If the first argument is a class, it is assumed to be the exception
|
110
|
+
# type that will be raised; if not, RuntimeError is raised as is normal
|
111
|
+
# with Kernel#raise. The remaining arguments are passed - via the
|
112
|
+
# <tt>*</tt> operator - to the class's constructor.
|
113
|
+
#
|
114
|
+
# All options passed to this method are respread - by the
|
115
|
+
# <tt>**</tt> operator - and passed to the underlying
|
116
|
+
# <tt>Kernel#raise</tt> call.
|
117
|
+
#
|
118
|
+
# === Exceptions
|
119
|
+
#
|
120
|
+
# - An instance of <tt>arg[0]</tt> if <tt>args[0].is_a?(::Class)</tt>; or
|
121
|
+
# - An instance of +RuntimeError+
|
122
|
+
def self.raise_with_options *args, **options
|
123
|
+
|
124
|
+
# special handling in case called indirectly
|
125
|
+
|
126
|
+
called_indirectly = options[:called_indirectly_06d353cb_5a6c_47ca_8dbe_ff76359c7e96]
|
127
|
+
|
128
|
+
case called_indirectly
|
129
|
+
when nil, false
|
130
|
+
|
131
|
+
called_indirectly = 0
|
132
|
+
when true
|
133
|
+
|
134
|
+
called_indirectly = 1
|
135
|
+
when ::Integer
|
136
|
+
|
137
|
+
;
|
138
|
+
else
|
139
|
+
|
140
|
+
abort "indirect-call option (#{called_indirectly}) has invalid type (#{called_indirectly.class})"
|
141
|
+
end
|
142
|
+
|
143
|
+
options.delete :called_indirectly_06d353cb_5a6c_47ca_8dbe_ff76359c7e96 if called_indirectly
|
144
|
+
|
145
|
+
|
146
|
+
# Use cases:
|
147
|
+
#
|
148
|
+
# 1. No options
|
149
|
+
# 2. Non-class and options
|
150
|
+
# 3. Class and options
|
151
|
+
# 3.a Class and options
|
152
|
+
# 3.b Class and options and message
|
153
|
+
# 3.c Class and options and message and call-stack
|
154
|
+
|
155
|
+
class_given = args.size > 0 && args[0].is_a?(::Class)
|
156
|
+
|
157
|
+
if class_given && !options.empty?
|
158
|
+
|
159
|
+
exception_class_or_instance_or_message_string = args.shift
|
160
|
+
|
161
|
+
# 3. Class and options
|
162
|
+
|
163
|
+
# 3.a Class and options
|
164
|
+
# 3.b Class and options and message
|
165
|
+
# 3.c Class and options and message and call-stack
|
166
|
+
|
167
|
+
|
168
|
+
xargs = []
|
169
|
+
|
170
|
+
xargs << args.shift unless args.empty?
|
171
|
+
|
172
|
+
x = exception_class_or_instance_or_message_string.new(*xargs, **options)
|
173
|
+
|
174
|
+
rargs = []
|
175
|
+
rargs << x
|
176
|
+
rargs += [ nil, args.shift ] unless args.empty?
|
177
|
+
|
178
|
+
# now need to trim backtrace
|
179
179
|
|
180
|
-
|
180
|
+
begin
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
Kernel.raise(*rargs)
|
183
|
+
rescue => x
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
185
|
+
bt = x.backtrace
|
186
|
+
(0..called_indirectly).each { bt.shift }
|
187
|
+
Kernel.raise x, x.message, bt
|
188
|
+
end
|
189
|
+
end
|
190
190
|
|
191
|
-
|
191
|
+
unless options.empty?
|
192
192
|
|
193
|
-
|
193
|
+
# 2. Non-class and options
|
194
194
|
|
195
|
-
|
196
|
-
|
195
|
+
warn "cannot utilise options in raise_with_options when first argument is non-class"
|
196
|
+
else
|
197
197
|
|
198
|
-
|
199
|
-
|
198
|
+
# 1. No options
|
199
|
+
end
|
200
200
|
|
201
201
|
|
202
|
-
|
202
|
+
# now need to trim backtrace
|
203
203
|
|
204
|
-
|
204
|
+
begin
|
205
205
|
|
206
|
-
|
207
|
-
|
206
|
+
Kernel.raise(*args)
|
207
|
+
rescue => x
|
208
208
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
209
|
+
bt = x.backtrace
|
210
|
+
(0..called_indirectly).each { bt.shift }
|
211
|
+
Kernel.raise x, x.message, bt
|
212
|
+
end
|
213
|
+
end
|
214
214
|
end # module ExceptionUtilities
|
215
215
|
|
216
216
|
end # module Diagnostics
|
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Definition of the WithCause inclusion module
|
6
6
|
#
|
7
7
|
# Created: 16th December 2017
|
8
|
-
# Updated:
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2019-
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -67,137 +67,137 @@ module Exceptions
|
|
67
67
|
#
|
68
68
|
module WithCause
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
# Array of hidden fields
|
71
|
+
INSPECT_HIDDEN_FIELDS = [ 'has_implicit_message', 'uses_cause_message' ]
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
# Defines an initializer for an exception class that allows a cause (aka
|
74
|
+
# an inner exception) to be specified, either as the first or last
|
75
|
+
# argument or as a +:cause+ option
|
76
|
+
#
|
77
|
+
# === Signature
|
78
|
+
#
|
79
|
+
# * *Parameters:*
|
80
|
+
# - +args+ 0+ arguments passed through to the +include+-ing class' initialiser
|
81
|
+
# - +options+ Options hash
|
82
|
+
#
|
83
|
+
# * *Options:*
|
84
|
+
# - +:cause+ - The exception to be used as a cause, and ensures that that is not inferred from the arguments. May be +nil+ to ensure that no cause is inferred
|
85
|
+
def initialize(*args, **options)
|
86
86
|
|
87
|
-
|
87
|
+
@uses_cause_message = false
|
88
88
|
|
89
|
-
|
89
|
+
cz = options[:cause]
|
90
90
|
|
91
|
-
|
91
|
+
if cz
|
92
92
|
|
93
|
-
|
93
|
+
options = options.reject { |k, v| k == :cause }
|
94
94
|
|
95
|
-
|
95
|
+
@has_implicit_message = args.empty?
|
96
96
|
|
97
|
-
|
97
|
+
super(*args)
|
98
98
|
|
99
|
-
|
99
|
+
warn 'unexpected implicit message' if @has_implicit_message && self.message != self.class.to_s
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
@cause = cz
|
102
|
+
else
|
103
103
|
|
104
|
-
|
104
|
+
cz_ix = args.index { |arg| ::Exception === arg }
|
105
105
|
|
106
|
-
|
106
|
+
if cz_ix
|
107
107
|
|
108
|
-
|
108
|
+
args = args.dup
|
109
109
|
|
110
|
-
|
110
|
+
cz = args.delete_at cz_ix
|
111
111
|
|
112
|
-
|
112
|
+
if args.empty?
|
113
113
|
|
114
|
-
|
114
|
+
if !(cz.message || '').empty? && cz.class.to_s != cz.message
|
115
115
|
|
116
|
-
|
116
|
+
@uses_cause_message = true
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
args = [ cz.message ]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
else
|
122
122
|
|
123
|
-
|
124
|
-
|
123
|
+
cz = $!
|
124
|
+
end
|
125
125
|
|
126
|
-
|
126
|
+
@has_implicit_message = args.empty?
|
127
127
|
|
128
|
-
|
128
|
+
super(*args)
|
129
129
|
|
130
|
-
|
130
|
+
warn 'unexpected implicit message' if @has_implicit_message && self.message != self.class.to_s
|
131
131
|
|
132
|
-
|
133
|
-
|
132
|
+
@cause = cz
|
133
|
+
end
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
@options = options
|
136
|
+
end
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
# The cause / inner-exception, if any, specified to the instance
|
139
|
+
# initialiser
|
140
|
+
attr_reader :cause
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
# The options passed to the initialiser, with +:cause+ removed, if
|
143
|
+
# present
|
144
|
+
attr_reader :options
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
146
|
+
# Message obtained by concatenation of all chained exceptions' messages
|
147
|
+
#
|
148
|
+
# === Signature
|
149
|
+
#
|
150
|
+
# * *Parameters:*
|
151
|
+
# - +options+ Options hash
|
152
|
+
#
|
153
|
+
# * *Options:*
|
154
|
+
# - +:separator+ (String) A string used to separate each chained exception message. Defaults to ": "
|
155
|
+
def chained_message **options
|
156
156
|
|
157
|
-
|
158
|
-
|
157
|
+
return message unless cause
|
158
|
+
return message if @uses_cause_message
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
m = message
|
161
|
+
c = cause
|
162
|
+
cm = c.respond_to?(:chained_message) ? c.chained_message(**options) : c.message
|
163
163
|
|
164
|
-
|
165
|
-
|
164
|
+
return m if (cm || '').empty?
|
165
|
+
return cm if (m || '').empty?
|
166
166
|
|
167
|
-
|
167
|
+
sep = options[:separator] || ': '
|
168
168
|
|
169
|
-
|
170
|
-
|
169
|
+
"#{m}#{sep}#{cm}"
|
170
|
+
end
|
171
171
|
|
172
|
-
|
173
|
-
|
172
|
+
# An array of exceptions in the chain, excluding +self+
|
173
|
+
def chainees
|
174
174
|
|
175
|
-
|
175
|
+
return [] unless cause
|
176
176
|
|
177
|
-
|
177
|
+
r = [ cause ]
|
178
178
|
|
179
|
-
|
179
|
+
r += cause.chainees if cause.respond_to? :chainees
|
180
180
|
|
181
|
-
|
182
|
-
|
181
|
+
r
|
182
|
+
end
|
183
183
|
|
184
|
-
|
185
|
-
|
184
|
+
# An array of exceptions in the chain, including +self+
|
185
|
+
def exceptions
|
186
186
|
|
187
|
-
|
188
|
-
|
187
|
+
[ self ] + chainees
|
188
|
+
end
|
189
189
|
|
190
|
-
|
191
|
-
|
190
|
+
# A combination of the backtrace(s) of all chained exception(s)
|
191
|
+
def chained_backtrace
|
192
192
|
|
193
|
-
|
193
|
+
b = backtrace
|
194
194
|
|
195
|
-
|
195
|
+
return b unless cause
|
196
196
|
|
197
|
-
|
197
|
+
cb = cause.respond_to?(:chained_backtrace) ? cause.chained_backtrace : cause.backtrace
|
198
198
|
|
199
|
-
|
200
|
-
|
199
|
+
(cb - b) + b
|
200
|
+
end
|
201
201
|
end
|
202
202
|
|
203
203
|
end # module Exceptions
|