debugtrace 0.2.5 → 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: 665b9852fb34caab345012ab6bac6e18c0e8951d689125ea9cf0c399a0c7637e
4
- data.tar.gz: d0940c27f8beec19e0aecfc609ddab7a35ecefedcde6251b1de5382d9d8ea319
3
+ metadata.gz: 7a1011528c478c032c1223c1fceb442bb32de6ba1ef40d9df2436b27718327c4
4
+ data.tar.gz: 5e11c1af69b68a0d8b380d7e4c09b703ad773ea43a23fb11cee1289827dfd926
5
5
  SHA512:
6
- metadata.gz: 3b3a87106db56eb5c88c42c28f5c25eaf17a19a502c82411853554200c7ddaa7c5117248d5b0059206a467b53a47abdf9e37a4aa4b736199f051b76cbe4ecd0d
7
- data.tar.gz: db33d2a6c4df894006aa1daada1fa777cdb0908ffeb4ccdb9b5de95e86dbece0835d0bea23a39c7f185dcf3fa36b6304ad680a185f58598a8cbe74b6d6bcb328
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
@@ -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.5'
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)
@@ -215,9 +216,7 @@ module DebugTrace
215
216
  double_quote_buff.no_break_append('"')
216
217
  single_quote_buff.no_break_append("'")
217
218
 
218
- return double_quote_buff if has_single_quote && !has_double_quote
219
-
220
- single_quote_buff
219
+ return has_single_quote && !has_double_quote ? double_quote_buff : single_quote_buff
221
220
  end
222
221
 
223
222
  def self.to_string_bytes(value, print_options)
@@ -278,7 +277,7 @@ module DebugTrace
278
277
  end
279
278
  buff.no_break_append(']')
280
279
 
281
- buff
280
+ return buff
282
281
  end
283
282
 
284
283
  def self.to_string_reflection(value, print_options)
@@ -304,7 +303,7 @@ module DebugTrace
304
303
  end
305
304
  buff.no_break_append('}')
306
305
 
307
- buff
306
+ return buff
308
307
  end
309
308
 
310
309
  def self.to_string_reflection_body(value, print_options)
@@ -328,7 +327,7 @@ module DebugTrace
328
327
  index += 1
329
328
  end
330
329
 
331
- buff
330
+ return buff
332
331
  end
333
332
 
334
333
  def self.to_string_enumerable(values, print_options)
@@ -367,7 +366,7 @@ module DebugTrace
367
366
 
368
367
  buff.no_break_append(close_char)
369
368
 
370
- buff
369
+ return buff
371
370
  end
372
371
 
373
372
  def self.to_string_enumerable_body(values, print_options)
@@ -401,7 +400,7 @@ module DebugTrace
401
400
 
402
401
  buff.no_break_append(':') if values.is_a?(Hash) && values.empty?
403
402
 
404
- buff
403
+ return buff
405
404
  end
406
405
 
407
406
  def self.to_string_key_value(key, value, print_options)
@@ -420,7 +419,7 @@ module DebugTrace
420
419
  type_name += @@config.size_format % count
421
420
  end
422
421
 
423
- type_name
422
+ return type_name
424
423
  end
425
424
 
426
425
  def self.has_to_s_method?(value)
@@ -501,7 +500,7 @@ module DebugTrace
501
500
  end
502
501
  end
503
502
 
504
- value
503
+ return value
505
504
  end
506
505
 
507
506
  def self.enter
@@ -537,10 +536,10 @@ module DebugTrace
537
536
  end
538
537
  end
539
538
 
540
- def self.leave
539
+ def self.leave(return_value = nil)
541
540
  @@thread_mutex.synchronize do
542
541
  print_start
543
- return unless @@config.enabled?
542
+ return return_value unless @@config.enabled?
544
543
 
545
544
  state = current_state
546
545
 
@@ -561,6 +560,7 @@ module DebugTrace
561
560
  )
562
561
  @@last_log_buff.line_feed
563
562
  @@logger.print(get_indent_string(state.nest_level, 0) + @@last_log_buff.lines[0].log)
563
+ return return_value
564
564
  end
565
565
  end
566
566
 
@@ -573,6 +573,6 @@ module DebugTrace
573
573
  state = current_state
574
574
  end
575
575
 
576
- "#{get_indent_string(state.nest_level, 0)}#{buff_string}"
576
+ return "#{get_indent_string(state.nest_level, 0)}#{buff_string}"
577
577
  end
578
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.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo