debugtrace 0.3.0 → 0.3.1
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 +4 -4
- data/debugtrace.yml +1 -0
- data/lib/debugtrace/log_buffer.rb +2 -5
- data/lib/debugtrace/version.rb +1 -1
- data/lib/debugtrace.rb +86 -60
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67184688a8a3f8b4a4ff9de1ef04799cf6957d9e94907c86073c083e3b6c1b98
|
4
|
+
data.tar.gz: c410dcd81f2aa49f307b20200fe487a335871bbec830c15ba2a900a022d9a309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fea6b71189147084795ad686aaca7c9621382a3516167f40a1811a4a7b889f4bd3a2d44823ed8a252a156ec42dc29f6f88919cd229ca287ea893f77ea35dc44
|
7
|
+
data.tar.gz: 625c317abee13df3c3e67bf2a2250f2d3685f341e9a2370b936f6c853b325f46571c47851d79827e96de4a850c196d0d308a912f23eae4f15e25bab15d6d4470
|
data/debugtrace.yml
CHANGED
@@ -86,17 +86,14 @@ class LogBuffer
|
|
86
86
|
|
87
87
|
# Appends lines of another LogBuffer.
|
88
88
|
#
|
89
|
-
# @param separator [String] the separator string to append if not ''
|
90
89
|
# @param buff [LogBuffer] another LogBuffer
|
91
90
|
# @return [LogBuffer] this object
|
92
|
-
def append_buffer(
|
93
|
-
Common.check_type('separator', separator, String)
|
91
|
+
def append_buffer(buff)
|
94
92
|
Common.check_type('buff', buff, LogBuffer)
|
95
|
-
append(separator, 0, true) if separator != ''
|
96
93
|
index = 0
|
97
94
|
for line in buff.lines
|
98
95
|
line_feed if index > 0
|
99
|
-
append(line.log, line.nest_level,
|
96
|
+
append(line.log, line.nest_level, true)
|
100
97
|
index += 1
|
101
98
|
end
|
102
99
|
return self
|
data/lib/debugtrace/version.rb
CHANGED
data/lib/debugtrace.rb
CHANGED
@@ -15,6 +15,10 @@ require_relative 'debugtrace/state'
|
|
15
15
|
|
16
16
|
# The main module of DebugTrace-rb.
|
17
17
|
module DebugTrace
|
18
|
+
@@no_reflection_classes = [
|
19
|
+
FalseClass, TrueClass, Integer, Float, Rational, Complex, Range, Regexp,
|
20
|
+
]
|
21
|
+
|
18
22
|
# Configuration values
|
19
23
|
@@config = nil
|
20
24
|
|
@@ -139,54 +143,58 @@ module DebugTrace
|
|
139
143
|
def self.to_string(name, value, print_options)
|
140
144
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
141
145
|
|
142
|
-
separator = ''
|
143
146
|
unless name.empty?
|
144
|
-
buff.append(name)
|
145
|
-
separator = @@config.varname_value_separator
|
147
|
+
buff.append(name).no_break_append(@@config.varname_value_separator)
|
146
148
|
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
buff.no_break_append(separator).append('nil')
|
151
|
-
when FalseClass, TrueClass, Integer, Float
|
152
|
-
buff.no_break_append(separator).append(value.to_s)
|
153
|
-
when Symbol
|
154
|
-
buff.no_break_append(separator).append(':').no_break_append(value.name)
|
155
|
-
when Class
|
156
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' class')
|
157
|
-
when Module
|
158
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' module')
|
159
|
-
when String
|
160
|
-
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
161
|
-
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
162
|
-
buff.append_buffer(separator, value_buff)
|
163
|
-
when DateTime
|
164
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
|
165
|
-
when Date
|
166
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d'))
|
167
|
-
when Time
|
168
|
-
buff.no_break_append(separator).append(value.strftime('%H:%M-%S.%L%:z'))
|
169
|
-
when Array, Set, Hash
|
170
|
-
value_buff = to_string_enumerable(value, print_options)
|
171
|
-
buff.append_buffer(separator, value_buff)
|
150
|
+
if @@no_reflection_classes.include?(value.class)
|
151
|
+
buff.append(value.to_s)
|
172
152
|
else
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
153
|
+
case value
|
154
|
+
when nil
|
155
|
+
buff.append('nil')
|
156
|
+
when Symbol
|
157
|
+
buff.append(':').no_break_append(value.name)
|
158
|
+
when Class
|
159
|
+
buff.append(value.name).no_break_append(' class')
|
160
|
+
when Module
|
161
|
+
buff.append(value.name).no_break_append(' module')
|
162
|
+
when String
|
163
|
+
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
164
|
+
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
165
|
+
buff.append_buffer(value_buff)
|
166
|
+
when DateTime, Time
|
167
|
+
buff.append(value.strftime('%Y-%m-%d %H:%M:%S.%L%:z'))
|
168
|
+
when Date
|
169
|
+
buff.append(value.strftime('%Y-%m-%d'))
|
170
|
+
when Dir, File
|
171
|
+
buff.append(value.class.name)
|
172
|
+
buff.append_buffer(to_string_str(value.path, print_options))
|
173
|
+
when Array, Set, Hash
|
174
|
+
value_buff = to_string_enumerable(value, print_options)
|
175
|
+
buff.append_buffer(value_buff)
|
176
|
+
else
|
177
|
+
reflection = print_options.reflection || value.class.superclass == Struct
|
178
|
+
|
179
|
+
to_s_string = reflection ? '' : value.to_s
|
180
|
+
if reflection || to_s_string.start_with?('#<')
|
181
|
+
# use reflection
|
182
|
+
value_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
183
|
+
if @@reflected_objects.any? { |obj| value.equal?(obj) }
|
184
|
+
# cyclic reference
|
185
|
+
value_buff.no_break_append(@@config.cyclic_reference_string)
|
186
|
+
elsif @@reflected_objects.length > print_options.reflection_limit
|
187
|
+
# over reflection level limitation
|
188
|
+
value_buff.no_break_append(@@config.limit_string)
|
189
|
+
else
|
190
|
+
@@reflected_objects.push(value)
|
191
|
+
value_buff = to_string_reflection(value, print_options)
|
192
|
+
@@reflected_objects.pop
|
193
|
+
end
|
194
|
+
buff.append_buffer(value_buff)
|
182
195
|
else
|
183
|
-
|
184
|
-
value_buff = to_string_reflection(value, print_options)
|
185
|
-
@@reflected_objects.pop
|
196
|
+
buff.append(to_s_string)
|
186
197
|
end
|
187
|
-
buff.append_buffer(separator, value_buff)
|
188
|
-
else
|
189
|
-
buff.no_break_append(separator).append(value.to_s)
|
190
198
|
end
|
191
199
|
end
|
192
200
|
|
@@ -202,7 +210,7 @@ module DebugTrace
|
|
202
210
|
single_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
203
211
|
double_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
204
212
|
|
205
|
-
if value.length >=
|
213
|
+
if value.length >= print_options.minimum_output_length
|
206
214
|
single_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
207
215
|
double_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
208
216
|
end
|
@@ -264,8 +272,8 @@ module DebugTrace
|
|
264
272
|
bytes_length = value.length
|
265
273
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
266
274
|
|
267
|
-
if bytes_length >=
|
268
|
-
buff.no_break_append(format(@@config.
|
275
|
+
if bytes_length >= print_options.minimum_output_length
|
276
|
+
buff.no_break_append(format(@@config.length_format, bytes_length))
|
269
277
|
end
|
270
278
|
|
271
279
|
buff.no_break_append('[')
|
@@ -321,7 +329,7 @@ module DebugTrace
|
|
321
329
|
def self.to_string_reflection(value, print_options)
|
322
330
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
323
331
|
|
324
|
-
buff.append(get_type_name(value))
|
332
|
+
buff.append(get_type_name(value, -1, print_options))
|
325
333
|
|
326
334
|
body_buff = to_string_reflection_body(value, print_options)
|
327
335
|
|
@@ -333,7 +341,7 @@ module DebugTrace
|
|
333
341
|
buff.up_nest
|
334
342
|
end
|
335
343
|
|
336
|
-
buff.append_buffer(
|
344
|
+
buff.append_buffer(body_buff)
|
337
345
|
|
338
346
|
if multi_lines
|
339
347
|
buff.line_feed if buff.length > 0
|
@@ -350,25 +358,42 @@ module DebugTrace
|
|
350
358
|
# @param print_options [PrintOptions] the print options
|
351
359
|
def self.to_string_reflection_body(value, print_options)
|
352
360
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
353
|
-
|
354
|
-
variables = value.instance_variables
|
355
|
-
|
356
361
|
multi_lines = false
|
357
362
|
index = 0
|
363
|
+
|
364
|
+
variables = value.instance_variables
|
358
365
|
variables.each do |variable|
|
359
366
|
buff.no_break_append(', ') if index > 0
|
360
367
|
|
361
368
|
var_value = value.instance_variable_get(variable)
|
362
369
|
member_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
363
|
-
member_buff.append(variable)
|
364
|
-
member_buff.append_buffer(
|
370
|
+
member_buff.append(variable).no_break_append(@@config.key_value_separator)
|
371
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
365
372
|
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
366
|
-
buff.append_buffer(
|
373
|
+
buff.append_buffer(member_buff)
|
367
374
|
|
368
375
|
multi_lines = member_buff.multi_lines?
|
369
376
|
index += 1
|
370
377
|
end
|
371
378
|
|
379
|
+
if value.class.superclass == Struct
|
380
|
+
members = value.members
|
381
|
+
hash = value.to_h
|
382
|
+
members.each do |member|
|
383
|
+
buff.no_break_append(', ') if index > 0
|
384
|
+
|
385
|
+
var_value = hash[member]
|
386
|
+
member_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
387
|
+
member_buff.append(member).no_break_append(@@config.key_value_separator)
|
388
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
389
|
+
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
390
|
+
buff.append_buffer(member_buff)
|
391
|
+
|
392
|
+
multi_lines = member_buff.multi_lines?
|
393
|
+
index += 1
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
372
397
|
return buff
|
373
398
|
end
|
374
399
|
|
@@ -391,7 +416,7 @@ module DebugTrace
|
|
391
416
|
end
|
392
417
|
|
393
418
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
394
|
-
buff.append(get_type_name(values, values.
|
419
|
+
buff.append(get_type_name(values, values.size, print_options))
|
395
420
|
buff.no_break_append(open_char)
|
396
421
|
|
397
422
|
body_buff = to_string_enumerable_body(values, print_options)
|
@@ -403,7 +428,7 @@ module DebugTrace
|
|
403
428
|
buff.up_nest
|
404
429
|
end
|
405
430
|
|
406
|
-
buff.append_buffer(
|
431
|
+
buff.append_buffer(body_buff)
|
407
432
|
|
408
433
|
if multi_lines
|
409
434
|
buff.line_feed
|
@@ -442,7 +467,7 @@ module DebugTrace
|
|
442
467
|
end
|
443
468
|
|
444
469
|
buff.line_feed if index > 0 && (multi_lines || element_buff.multi_lines?)
|
445
|
-
buff.append_buffer(
|
470
|
+
buff.append_buffer(element_buff)
|
446
471
|
|
447
472
|
multi_lines = element_buff.multi_lines?
|
448
473
|
index += 1
|
@@ -462,19 +487,20 @@ module DebugTrace
|
|
462
487
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
463
488
|
key_buff = to_string('', key, print_options)
|
464
489
|
value_buff = to_string('', value, print_options)
|
465
|
-
buff.append_buffer(
|
490
|
+
buff.append_buffer(key_buff).no_break_append(@@config.key_value_separator).append_buffer(value_buff)
|
466
491
|
buff
|
467
492
|
end
|
468
493
|
|
469
494
|
# Returns the type name.
|
470
495
|
#
|
471
496
|
# @param value [Object] the value
|
472
|
-
# @
|
473
|
-
|
497
|
+
# @param size [Object] the size of Array, Set or Hash
|
498
|
+
# @param print_options [PrintOptions] the print options
|
499
|
+
def self.get_type_name(value, size, print_options)
|
474
500
|
type_name = value.class.to_s
|
475
501
|
type_name = '' if %w[Array Hash Set].include?(type_name)
|
476
502
|
|
477
|
-
if size >=
|
503
|
+
if size >= print_options.minimum_output_size
|
478
504
|
type_name += @@config.size_format % size
|
479
505
|
end
|
480
506
|
|