xqsr3 0.38.1.1 → 0.39.1
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 +13 -13
- data/examples/count_word_frequencies.rb +5 -5
- data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +405 -404
- data/lib/xqsr3/containers/multi_map.rb +454 -453
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +56 -57
- data/lib/xqsr3/conversion/integer_parser.rb +92 -93
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
- data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +136 -136
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
- data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
- 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 +34 -34
- data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
- 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 -5
- 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 -2
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -2
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
- data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
- data/lib/xqsr3/io/writelines.rb +125 -125
- data/lib/xqsr3/quality/parameter_checking.rb +452 -453
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
- data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
- data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
- data/lib/xqsr3/string_utilities/truncate.rb +60 -61
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +19 -20
- data/test/performance/frequency_map.rb +13 -27
- data/test/scratch/test_assert_raise_with_message.rb +12 -13
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +607 -554
- data/test/unit/containers/tc_multi_map.rb +573 -522
- data/test/unit/conversion/tc_integer_parser.rb +73 -73
- data/test/unit/conversion/tc_to_bool.rb +26 -26
- 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_hash.rb +1 -1
- data/test/unit/extensions/hash/tc_slice.rb +14 -14
- 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 +77 -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 +51 -51
- 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 +106 -108
- data/test/unit/quality/tc_parameter_checking.rb +390 -390
- data/test/unit/string_utilities/tc_truncate.rb +28 -28
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -1,17 +1,18 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/diagnostics/exception_utilities.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Definition of the ExceptionUtilities module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 12th February 2015
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c)
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
|
+
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
17
18
|
# Redistribution and use in source and binary forms, with or without
|
@@ -25,7 +26,7 @@
|
|
25
26
|
# notice, this list of conditions and the following disclaimer in the
|
26
27
|
# documentation and/or other materials provided with the distribution.
|
27
28
|
#
|
28
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
29
30
|
# contributors may be used to endorse or promote products derived from
|
30
31
|
# this software without specific prior written permission.
|
31
32
|
#
|
@@ -55,161 +56,161 @@ module Diagnostics
|
|
55
56
|
|
56
57
|
module ExceptionUtilities
|
57
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
|
-
|
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
|
178
179
|
|
179
|
-
|
180
|
+
begin
|
180
181
|
|
181
|
-
|
182
|
-
|
182
|
+
Kernel.raise(*rargs)
|
183
|
+
rescue => x
|
183
184
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
185
|
+
bt = x.backtrace
|
186
|
+
(0..called_indirectly).each { bt.shift }
|
187
|
+
Kernel.raise x, x.message, bt
|
188
|
+
end
|
189
|
+
end
|
189
190
|
|
190
|
-
|
191
|
+
unless options.empty?
|
191
192
|
|
192
|
-
|
193
|
+
# 2. Non-class and options
|
193
194
|
|
194
|
-
|
195
|
-
|
195
|
+
warn "cannot utilise options in raise_with_options when first argument is non-class"
|
196
|
+
else
|
196
197
|
|
197
|
-
|
198
|
-
|
198
|
+
# 1. No options
|
199
|
+
end
|
199
200
|
|
200
201
|
|
201
|
-
|
202
|
+
# now need to trim backtrace
|
202
203
|
|
203
|
-
|
204
|
+
begin
|
204
205
|
|
205
|
-
|
206
|
-
|
206
|
+
Kernel.raise(*args)
|
207
|
+
rescue => x
|
207
208
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
bt = x.backtrace
|
210
|
+
(0..called_indirectly).each { bt.shift }
|
211
|
+
Kernel.raise x, x.message, bt
|
212
|
+
end
|
213
|
+
end
|
213
214
|
end # module ExceptionUtilities
|
214
215
|
|
215
216
|
end # module Diagnostics
|
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/diagnostics/exceptions/with_cause.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Definition of the WithCause inclusion module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 16th December 2017
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -25,7 +26,7 @@
|
|
25
26
|
# notice, this list of conditions and the following disclaimer in the
|
26
27
|
# documentation and/or other materials provided with the distribution.
|
27
28
|
#
|
28
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
29
30
|
# contributors may be used to endorse or promote products derived from
|
30
31
|
# this software without specific prior written permission.
|
31
32
|
#
|
@@ -66,139 +67,142 @@ module Exceptions
|
|
66
67
|
#
|
67
68
|
module WithCause
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
# Array of hidden fields
|
71
|
+
INSPECT_HIDDEN_FIELDS = [ 'has_implicit_message', 'uses_cause_message' ]
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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)
|
85
86
|
|
86
|
-
|
87
|
+
@uses_cause_message = false
|
87
88
|
|
88
|
-
|
89
|
+
cz = options[:cause]
|
89
90
|
|
90
|
-
|
91
|
+
if cz
|
91
92
|
|
92
|
-
|
93
|
+
options = options.reject { |k, v| k == :cause }
|
93
94
|
|
94
|
-
|
95
|
+
@has_implicit_message = args.empty?
|
95
96
|
|
96
|
-
|
97
|
+
super(*args)
|
97
98
|
|
98
|
-
|
99
|
+
warn 'unexpected implicit message' if @has_implicit_message && self.message != self.class.to_s
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
@cause = cz
|
102
|
+
else
|
102
103
|
|
103
|
-
|
104
|
+
cz_ix = args.index { |arg| ::Exception === arg }
|
104
105
|
|
105
|
-
|
106
|
+
if cz_ix
|
106
107
|
|
107
|
-
|
108
|
+
args = args.dup
|
108
109
|
|
109
|
-
|
110
|
+
cz = args.delete_at cz_ix
|
110
111
|
|
111
|
-
|
112
|
+
if args.empty?
|
112
113
|
|
113
|
-
|
114
|
+
if !(cz.message || '').empty? && cz.class.to_s != cz.message
|
114
115
|
|
115
|
-
|
116
|
+
@uses_cause_message = true
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
args = [ cz.message ]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
else
|
121
122
|
|
122
|
-
|
123
|
-
|
123
|
+
cz = $!
|
124
|
+
end
|
124
125
|
|
125
|
-
|
126
|
+
@has_implicit_message = args.empty?
|
126
127
|
|
127
|
-
|
128
|
+
super(*args)
|
128
129
|
|
129
|
-
|
130
|
+
warn 'unexpected implicit message' if @has_implicit_message && self.message != self.class.to_s
|
130
131
|
|
131
|
-
|
132
|
-
|
132
|
+
@cause = cz
|
133
|
+
end
|
133
134
|
|
134
|
-
|
135
|
-
|
135
|
+
@options = options
|
136
|
+
end
|
136
137
|
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
# The cause / inner-exception, if any, specified to the instance
|
139
|
+
# initialiser
|
140
|
+
attr_reader :cause
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
# The options passed to the initialiser, with +:cause+ removed, if
|
143
|
+
# present
|
144
|
+
attr_reader :options
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
155
156
|
|
156
|
-
|
157
|
-
|
157
|
+
return message unless cause
|
158
|
+
return message if @uses_cause_message
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
160
|
+
m = message
|
161
|
+
c = cause
|
162
|
+
cm = c.respond_to?(:chained_message) ? c.chained_message(**options) : c.message
|
162
163
|
|
163
|
-
|
164
|
-
|
164
|
+
return m if (cm || '').empty?
|
165
|
+
return cm if (m || '').empty?
|
165
166
|
|
166
|
-
|
167
|
+
sep = options[:separator] || ': '
|
167
168
|
|
168
|
-
|
169
|
-
|
169
|
+
"#{m}#{sep}#{cm}"
|
170
|
+
end
|
170
171
|
|
171
|
-
|
172
|
-
|
172
|
+
# An array of exceptions in the chain, excluding +self+
|
173
|
+
def chainees
|
173
174
|
|
174
|
-
|
175
|
+
return [] unless cause
|
175
176
|
|
176
|
-
|
177
|
+
r = [ cause ]
|
177
178
|
|
178
|
-
|
179
|
+
r += cause.chainees if cause.respond_to? :chainees
|
179
180
|
|
180
|
-
|
181
|
-
|
181
|
+
r
|
182
|
+
end
|
182
183
|
|
183
|
-
|
184
|
-
|
184
|
+
# An array of exceptions in the chain, including +self+
|
185
|
+
def exceptions
|
185
186
|
|
186
|
-
|
187
|
-
|
187
|
+
[ self ] + chainees
|
188
|
+
end
|
188
189
|
|
189
|
-
|
190
|
-
|
190
|
+
# A combination of the backtrace(s) of all chained exception(s)
|
191
|
+
def chained_backtrace
|
191
192
|
|
192
|
-
|
193
|
+
b = backtrace
|
193
194
|
|
194
|
-
|
195
|
+
return b unless cause
|
195
196
|
|
196
|
-
|
197
|
+
cb = cause.respond_to?(:chained_backtrace) ? cause.chained_backtrace : cause.backtrace
|
197
198
|
|
198
|
-
|
199
|
-
|
199
|
+
(cb - b) + b
|
200
|
+
end
|
200
201
|
end
|
201
202
|
|
202
203
|
end # module Exceptions
|
203
204
|
end # module Diagnostics
|
204
205
|
end # module Xqsr3
|
206
|
+
|
207
|
+
# ############################## end of file ############################# #
|
208
|
+
|