debugtrace 0.2.4 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce8fe4113e5e6d49353414a4e204e96fd0bb18f303972a5e4aef48e0e7fa07d5
4
- data.tar.gz: 0cdba9d53b9edbed09ef2ed76a76756abdc57fe5fbabd7ab886d06e3ab1d1623
3
+ metadata.gz: 7a1011528c478c032c1223c1fceb442bb32de6ba1ef40d9df2436b27718327c4
4
+ data.tar.gz: 5e11c1af69b68a0d8b380d7e4c09b703ad773ea43a23fb11cee1289827dfd926
5
5
  SHA512:
6
- metadata.gz: cbdba0458650b624c0a7e6872c294f578e855fd3cb5d6e050ec4801a356a94fd29b3c3f5a00e01ef155860a8cde98e7b093c2f5f1b1cf5f0925c1904536e17d9
7
- data.tar.gz: 34acc1fc0519aea58496c807f7716944696f596f2810d6403cee8c9e7b1184f29579420ab58cbe3a310d895e43ee9b351f90112c5d9154f71dfb5983075b58a1
6
+ metadata.gz: a74c1b4784462f0ebc6a6b40d55c9ebba4df3bd087ec5e421fecd8b0c79cdda06404fa7e5c914d83ddccd96b6aa3dadeef0d21b1f53a3164cbcf0c7932b86298
7
+ data.tar.gz: e6b556af241a5976d6e7731138cb48d3059ce90b0ec4b274d3844da134532ed0156280bb37d85ae7d03106d1ea855dd399723ba41546fbdd42b71221a41b65e1
@@ -30,6 +30,6 @@ module Common
30
30
  top_type_name == 'E' || top_type_name == 'O' ? 'an' : 'a'
31
31
  raise "Argument #{value_name} (=#{value_string}) must be #{a} #{type}"
32
32
  end
33
- value
33
+ return value
34
34
  end
35
35
  end
@@ -62,10 +62,10 @@ class Config
62
62
  @varname_value_separator = get_value 'varname_value_separator' , ' = '
63
63
  @key_value_separator = get_value 'key_value_separator' , ': '
64
64
  @print_suffix_format = get_value 'print_suffix_format' , ' (%2$s:%3$d)'
65
- @size_format = get_value 'size_format' , 'size:%d'
66
- @minimum_output_size = get_value 'minimum_output_size' , 16
67
- @length_format = get_value 'length_format' , 'length:%d'
68
- @minimum_output_length = get_value 'minimum_output_length' , 16
65
+ @size_format = get_value 'size_format' , '(size:%d)'
66
+ @minimum_output_size = get_value 'minimum_output_size' , 256
67
+ @length_format = get_value 'length_format' , '(length:%d)'
68
+ @minimum_output_length = get_value 'minimum_output_length' , 256
69
69
  @maximum_data_output_width = get_value 'maximum_data_output_width', 70
70
70
  @bytes_count_in_line = get_value 'bytes_count_in_line' , 16
71
71
  @collection_limit = get_value 'collection_limit' , 128
@@ -77,7 +77,7 @@ class Config
77
77
  # Returns true if logging is enabled, false otherwise.
78
78
  # @return true if logging is enabled, false otherwise
79
79
  def enabled?
80
- @enabled
80
+ return @enabled
81
81
  end
82
82
 
83
83
  private
@@ -97,6 +97,6 @@ class Config
97
97
  Common.check_type("config[#{key}]", value, defalut_value.class)
98
98
  end
99
99
  end
100
- value
100
+ return value
101
101
  end
102
102
  end
@@ -15,7 +15,7 @@ class LogBuffer
15
15
  attr_reader :nest_level, :log
16
16
 
17
17
  def to_s
18
- "(LogBuffer.LevelAndLog){nest_level: #{@nest_level}, log: \"#{@log}\"}"
18
+ return "(LogBuffer.LevelAndLog){nest_level: #{@nest_level}, log: \"#{@log}\"}"
19
19
  end
20
20
  end
21
21
 
@@ -64,7 +64,7 @@ class LogBuffer
64
64
  @append_nest_level = nest_level
65
65
  @last_line += string
66
66
  end
67
- self
67
+ return self
68
68
  end
69
69
 
70
70
  # Appends a string representation of the value.
@@ -72,7 +72,7 @@ class LogBuffer
72
72
  # @param value [Object] The value to append
73
73
  # @return LogBuffer: This object
74
74
  def no_break_append(value)
75
- append(value, 0, true)
75
+ return append(value, 0, true)
76
76
  end
77
77
 
78
78
  # Appends lines of another LogBuffer.
@@ -90,23 +90,23 @@ class LogBuffer
90
90
  append(line.log, line.nest_level, index == 0 && separator != '')
91
91
  index += 1
92
92
  end
93
- self
93
+ return self
94
94
  end
95
95
 
96
96
  # The length of the last line.
97
97
  def length
98
- @last_line.length
98
+ return @last_line.length
99
99
  end
100
100
 
101
101
  # true if multiple line, false otherwise.
102
102
  def multi_lines?
103
- @lines.length > 1 || @lines.length == 1 && length > 0
103
+ return @lines.length > 1 || @lines.length == 1 && length > 0
104
104
  end
105
105
 
106
106
  # A list of tuple of data indentation level && log string.
107
107
  def lines
108
108
  lines = @lines.dup
109
109
  lines << LevelAndLog.new(@nest_level, @last_line) if length > 0
110
- lines
110
+ return lines
111
111
  end
112
112
  end
@@ -16,7 +16,7 @@ class LoggerBase
16
16
  # Returns a string representation of this object.
17
17
  # @return [String] A string representation of this object
18
18
  def to_s
19
- "#{self.class.name}"
19
+ return "#{self.class.name}"
20
20
  end
21
21
  end
22
22
 
@@ -85,12 +85,13 @@ class RubyLogger
85
85
  def print(message)
86
86
  Common::check_type("message", message, String)
87
87
  @logger.log(Logger::Severity::DEBUG, message, 'DebugTrace-rb')
88
+ return message
88
89
  end
89
90
 
90
91
  # Returns a string representation of this object.
91
92
  # @return [String] A string representation of this object
92
93
  def to_s
93
- "Ruby #{Logger.name} path: #{@config.log_path}"
94
+ return "Ruby #{Logger.name} path: #{@config.log_path}"
94
95
  end
95
96
  end
96
97
 
@@ -132,11 +133,12 @@ class FileLogger < LoggerBase
132
133
  file.puts "#{datetime_str} #{message}"
133
134
  }
134
135
  end
136
+ return message
135
137
  end
136
138
 
137
139
  # Returns a string representation of this object.
138
140
  # @return [String] A string representation of this object
139
141
  def to_s
140
- "#{self.class.name} path: #{@log_path}, append: #{@append}"
142
+ return "#{self.class.name} path: #{@log_path}, append: #{@append}"
141
143
  end
142
144
  end
@@ -5,46 +5,23 @@ require_relative 'common'
5
5
  # Have the trace state for a thread
6
6
  # @author Masato Kokubo
7
7
  class State
8
+ attr_reader :thread_id
9
+ attr_reader :nest_level
10
+ attr_reader :previous_nest_level
11
+
8
12
  def initialize(thread_id)
9
- @thread_id = Common::check_type('thread_id', thread_id, Integer)
13
+ @thread_id = thread_id
10
14
  reset()
11
15
  end
12
16
 
13
- # @return the thread id.
14
- def thread_id
15
- @thread_id
16
- end
17
-
18
- # @return the nest level.
19
- def nest_level
20
- @nest_level
21
- end
22
-
23
- # @return the previous nest level.
24
- def previous_nest_level
25
- @previous_nest_level
26
- end
27
-
28
- # @return the previous line count.
29
- def previous_line_count
30
- @previous_line_count
31
- end
32
-
33
- # Sets the previous line count.
34
- # @param value the previous line count
35
- def previous_line_count=(value)
36
- @previous_line_count = Common::check_type('value', value, Integer)
37
- end
38
-
39
17
  def reset
40
18
  @nest_level = 0
41
19
  @previous_nest_level = 0
42
- @previous_line_count = 0
43
20
  @times = []
44
21
  end
45
22
 
46
23
  def to_s()
47
- "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, previous_line_count: #{@previous_line_count}, times: #{@times}}"
24
+ return "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, times: #{@times}}"
48
25
  end
49
26
 
50
27
  # Ups the nest level.
@@ -54,6 +31,7 @@ class State
54
31
  @times.push(Time.now)
55
32
  end
56
33
  @nest_level += 1
34
+ return nil
57
35
  end
58
36
 
59
37
  #Downs the nest level.
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DebugTrace
5
- VERSION = '0.2.4'
5
+ VERSION = '0.2.6'
6
6
  end
data/lib/debugtrace.rb CHANGED
@@ -16,7 +16,7 @@ module DebugTrace
16
16
  @@config = nil
17
17
 
18
18
  def self.config
19
- @@config
19
+ return @@config
20
20
  end
21
21
 
22
22
  # A Mutex for thread safety
@@ -59,8 +59,9 @@ module DebugTrace
59
59
 
60
60
  return unless @@config.enabled?
61
61
 
62
+ config_path = File.expand_path(@@config.config_path)
62
63
  @@logger.print("DebugTrace-rb #{DebugTrace::VERSION} on Ruby #{RUBY_VERSION}")
63
- @@logger.print(" config file: #{@@config.config_path}")
64
+ @@logger.print(" config file: #{config_path}")
64
65
  @@logger.print(" logger: #{@@logger}")
65
66
  end
66
67
 
@@ -95,13 +96,13 @@ module DebugTrace
95
96
  @@state_hash[thread_id] = state
96
97
  end
97
98
 
98
- state
99
+ return state
99
100
  end
100
101
 
101
102
  def self.get_indent_string(nest_level, data_nest_level)
102
103
  indent_str = @@config.indent_string * [[0, nest_level].max, @@config.maximum_indents].min
103
104
  data_indent_str = @@config.data_indent_string * [[0, data_nest_level].max, @@config.maximum_indents].min
104
- indent_str + data_indent_str
105
+ return indent_str + data_indent_str
105
106
  end
106
107
 
107
108
  def self.to_string(name, value, print_options)
@@ -153,7 +154,7 @@ module DebugTrace
153
154
  buff.append_buffer(separator, value_buff)
154
155
  end
155
156
 
156
- buff
157
+ return buff
157
158
  end
158
159
 
159
160
  def self.to_string_str(value, print_options)
@@ -163,12 +164,8 @@ module DebugTrace
163
164
  double_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
164
165
 
165
166
  if value.length >= @@config.minimum_output_length
166
- single_quote_buff.no_break_append('(')
167
167
  single_quote_buff.no_break_append(format(@@config.length_format, value.length))
168
- single_quote_buff.no_break_append(')')
169
- double_quote_buff.no_break_append('(')
170
168
  double_quote_buff.no_break_append(format(@@config.length_format, value.length))
171
- double_quote_buff.no_break_append(')')
172
169
  end
173
170
 
174
171
  single_quote_buff.no_break_append("'")
@@ -219,9 +216,7 @@ module DebugTrace
219
216
  double_quote_buff.no_break_append('"')
220
217
  single_quote_buff.no_break_append("'")
221
218
 
222
- return double_quote_buff if has_single_quote && !has_double_quote
223
-
224
- single_quote_buff
219
+ return has_single_quote && !has_double_quote ? double_quote_buff : single_quote_buff
225
220
  end
226
221
 
227
222
  def self.to_string_bytes(value, print_options)
@@ -236,11 +231,10 @@ module DebugTrace
236
231
  end
237
232
 
238
233
  if bytes_length >= @@config.minimum_output_length
239
- buff.no_break_append(' ')
240
234
  buff.no_break_append(format(@@config.size_format, bytes_length))
241
235
  end
242
236
 
243
- buff.no_break_append(') [')
237
+ buff.no_break_append('[')
244
238
 
245
239
  multi_lines = bytes_length >= @@config.bytes_count_in_line
246
240
 
@@ -283,7 +277,7 @@ module DebugTrace
283
277
  end
284
278
  buff.no_break_append(']')
285
279
 
286
- buff
280
+ return buff
287
281
  end
288
282
 
289
283
  def self.to_string_reflection(value, print_options)
@@ -309,7 +303,7 @@ module DebugTrace
309
303
  end
310
304
  buff.no_break_append('}')
311
305
 
312
- buff
306
+ return buff
313
307
  end
314
308
 
315
309
  def self.to_string_reflection_body(value, print_options)
@@ -333,7 +327,7 @@ module DebugTrace
333
327
  index += 1
334
328
  end
335
329
 
336
- buff
330
+ return buff
337
331
  end
338
332
 
339
333
  def self.to_string_enumerable(values, print_options)
@@ -372,7 +366,7 @@ module DebugTrace
372
366
 
373
367
  buff.no_break_append(close_char)
374
368
 
375
- buff
369
+ return buff
376
370
  end
377
371
 
378
372
  def self.to_string_enumerable_body(values, print_options)
@@ -406,7 +400,7 @@ module DebugTrace
406
400
 
407
401
  buff.no_break_append(':') if values.is_a?(Hash) && values.empty?
408
402
 
409
- buff
403
+ return buff
410
404
  end
411
405
 
412
406
  def self.to_string_key_value(key, value, print_options)
@@ -422,11 +416,10 @@ module DebugTrace
422
416
  type_name = '' if %w[Array Hash Set].include?(type_name)
423
417
 
424
418
  if count >= @@config.minimum_output_size
425
- type_name += ' ' unless type_name.empty?
426
419
  type_name += @@config.size_format % count
427
420
  end
428
421
 
429
- type_name
422
+ return type_name
430
423
  end
431
424
 
432
425
  def self.has_to_s_method?(value)
@@ -507,7 +500,7 @@ module DebugTrace
507
500
  end
508
501
  end
509
502
 
510
- value
503
+ return value
511
504
  end
512
505
 
513
506
  def self.enter
@@ -543,10 +536,10 @@ module DebugTrace
543
536
  end
544
537
  end
545
538
 
546
- def self.leave
539
+ def self.leave(return_value = nil)
547
540
  @@thread_mutex.synchronize do
548
541
  print_start
549
- return unless @@config.enabled?
542
+ return return_value unless @@config.enabled?
550
543
 
551
544
  state = current_state
552
545
 
@@ -567,6 +560,7 @@ module DebugTrace
567
560
  )
568
561
  @@last_log_buff.line_feed
569
562
  @@logger.print(get_indent_string(state.nest_level, 0) + @@last_log_buff.lines[0].log)
563
+ return return_value
570
564
  end
571
565
  end
572
566
 
@@ -579,6 +573,6 @@ module DebugTrace
579
573
  state = current_state
580
574
  end
581
575
 
582
- "#{get_indent_string(state.nest_level, 0)}#{buff_string}"
576
+ return "#{get_indent_string(state.nest_level, 0)}#{buff_string}"
583
577
  end
584
578
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debugtrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo