debugtrace 0.2.0 → 0.2.2

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: 8605af0f8e17c3dffcef132208a051bc3cda499dfb664c669ccc58fe9783055b
4
- data.tar.gz: 3eb3fca8224a904ea1d9856748feb8ec3b97395ef5c1dff302827de358b0fa9d
3
+ metadata.gz: 5937a3c3f6b9d19ab3bb040ef763ada32e262c5046532331a7082f3edc3128cb
4
+ data.tar.gz: 31b5c3027993f50d06409ec9c54d55adff5e68563a8f02b66ae6e618027ec550
5
5
  SHA512:
6
- metadata.gz: c77f35231079526344c403ccd7b2753cfc4a81bb656459acc4a99b69548ad46f65c9f6cf628dc3c516c2c65ceaceabace8d2325f8cb5e1d690d449d5c190c242
7
- data.tar.gz: 6cee3b4fe007601cab14db3123be8e93db6841c8e95847c8e3724ad00f9ef893b9347de807f4b54764a5726f8b14b87a286cc11168be72e1f27f1f56c5c58cd7
6
+ metadata.gz: 33e2b5d74dcfcabfc0868652118694478e47ad5c6066e70c75090b50db7dc61008cfdfe5d4a9b438d7d7a2df91be97110d3766bfbbbd43536dfbaeacf0414c22
7
+ data.tar.gz: bd78a8be204cd636d3104d06e3ff777ade2458f0492c5e50fd6f115f7108d290d4348cf02454721ca2680ef6a872455122b50e95fa836e8f9ed7efb1a17e7e6b
@@ -38,7 +38,7 @@ class Config
38
38
  @collection_limit = _get_config_value 'collection_limit' , 128
39
39
  @bytes_limit = _get_config_value 'bytes_limit' , 256
40
40
  @string_limit = _get_config_value 'string_limit' , 256
41
- @reflection_nest_limit = _get_config_value 'reflection_nest_limit' , 4
41
+ @reflection_limit = _get_config_value 'reflection_limit' , 4
42
42
  end
43
43
 
44
44
  attr_reader :config_path, :logger_name, :logging_destination, :logging_format, :logging_datetime_format,
@@ -47,7 +47,7 @@ class Config
47
47
  :cyclic_reference_string, :varname_value_separator, :key_value_separator,
48
48
  :print_suffix_format, :count_format, :minimum_output_count, :length_format,
49
49
  :minimum_output_length, :maximum_data_output_width, :bytes_count_in_line,
50
- :collection_limit, :bytes_limit, :string_limit, :reflection_nest_limit
50
+ :collection_limit, :bytes_limit, :string_limit, :reflection_limit
51
51
 
52
52
  def enabled? = @enabled
53
53
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DebugTrace
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.2'
6
6
  end
data/lib/debugtrace.rb CHANGED
@@ -64,27 +64,23 @@ module DebugTrace
64
64
  end
65
65
 
66
66
  class PrintOptions
67
- attr_reader :force_reflection,
68
- # :output_private, :output_method,
69
- :minimum_output_count, :minimum_output_length,
70
- :collection_limit, :bytes_limit, :string_limit, :reflection_nest_limit
67
+ attr_reader :minimum_output_count, :minimum_output_length,
68
+ :collection_limit, :bytes_limit, :string_limit, :reflection_limit
71
69
 
72
70
  def initialize(
73
- force_reflection,
74
71
  minimum_output_count,
75
72
  minimum_output_length,
76
73
  collection_limit,
77
74
  bytes_limit,
78
75
  string_limit,
79
- reflection_nest_limit
76
+ reflection_limit
80
77
  )
81
- @force_reflection = force_reflection
82
78
  @minimum_output_count = minimum_output_count == -1 ? DebugTrace.config.minimum_output_count : minimum_output_count
83
79
  @minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
84
80
  @collection_limit = collection_limit == -1 ? DebugTrace.config.collection_limit : collection_limit
85
81
  @bytes_limit = bytes_limit == -1 ? DebugTrace.config.bytes_limit : bytes_limit
86
82
  @string_limit = string_limit == -1 ? DebugTrace.config.string_limit : string_limit
87
- @reflection_nest_limit = reflection_nest_limit == -1 ? DebugTrace.config.reflection_nest_limit : reflection_nest_limit
83
+ @reflection_limit = reflection_limit == -1 ? DebugTrace.config.reflection_limit : reflection_limit
88
84
  end
89
85
  end
90
86
 
@@ -118,50 +114,36 @@ module DebugTrace
118
114
 
119
115
  case value
120
116
  when nil
121
- # nil
122
117
  buff.no_break_append(separator).append('nil')
123
- when String # ''.class # String
124
- # String
118
+ when FalseClass, TrueClass, Integer, Float
119
+ buff.no_break_append(separator).append(value.to_s)
120
+ when String
125
121
  value_buff = to_string_str(value, print_options)
126
122
  buff.append_buffer(separator, value_buff)
127
123
  when DateTime
128
- # DateTime
129
124
  buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
130
125
  when Date
131
- # DateTime
132
126
  buff.no_break_append(separator).append(value.strftime('%Y-%m-%d'))
133
127
  when Time
134
- # DateTime
135
128
  buff.no_break_append(separator).append(value.strftime('%H:%M-%S.%L%:z'))
136
- when Integer, Float
137
- # Integer, Float, Date, Time
138
- buff.no_break_append(separator).append(value.to_s)
139
129
  when Array, Set, Hash
140
- # Array, Set, Hash
141
130
  value_buff = to_string_enumerable(value, print_options)
142
131
  buff.append_buffer(separator, value_buff)
143
132
  else
133
+ # use reflection
144
134
  value_buff = LogBuffer.new(@@config.maximum_data_output_width)
145
- if !print_options.force_reflection && has_to_s_method?(value)
146
- # has to_s or inspect method
147
- value_buff.append('to_s: ')
148
- value_buff.no_break_append(value.to_s)
149
- buff.append_buffer(separator, value_buff)
135
+ if @@reflected_objects.any? { |obj| value.equal?(obj) }
136
+ # cyclic reference
137
+ value_buff.no_break_append(@@config.cyclic_reference_string)
138
+ elsif @@reflected_objects.length > print_options.reflection_limit
139
+ # over reflection level limitation
140
+ value_buff.no_break_append(@@config.limit_string)
150
141
  else
151
- # use reflection
152
- if @@reflected_objects.any? { |obj| value.equal?(obj) }
153
- # cyclic reference
154
- value_buff.no_break_append(@@config.cyclic_reference_string)
155
- elsif @@reflected_objects.length > print_options.reflection_nest_limit
156
- # over reflection level limitation
157
- value_buff.no_break_append(@@config.limit_string)
158
- else
159
- @@reflected_objects.push(value)
160
- value_buff = to_string_reflection(value, print_options)
161
- @@reflected_objects.pop
162
- end
163
- buff.append_buffer(separator, value_buff)
142
+ @@reflected_objects.push(value)
143
+ value_buff = to_string_reflection(value, print_options)
144
+ @@reflected_objects.pop
164
145
  end
146
+ buff.append_buffer(separator, value_buff)
165
147
  end
166
148
 
167
149
  buff
@@ -470,10 +452,10 @@ module DebugTrace
470
452
 
471
453
  @@DO_NOT_OUTPUT = 'Do not output'
472
454
 
473
- def self.print(name, value = @@DO_NOT_OUTPUT, force_reflection: false,
455
+ def self.print(name, value = @@DO_NOT_OUTPUT,
474
456
  minimum_output_count: -1, minimum_output_length: -1,
475
457
  collection_limit: -1, bytes_limit: -1,
476
- string_limit: -1, reflection_nest_limit: -1)
458
+ string_limit: -1, reflection_limit: -1)
477
459
  @@thread_mutex.synchronize do
478
460
  print_start
479
461
  return value unless @@config.enabled?
@@ -490,10 +472,9 @@ module DebugTrace
490
472
  else
491
473
  # with value
492
474
  print_options = PrintOptions.new(
493
- force_reflection,
494
475
  minimum_output_count, minimum_output_length,
495
476
  collection_limit, bytes_limit,
496
- string_limit, reflection_nest_limit
477
+ string_limit, reflection_limit
497
478
  )
498
479
  @@last_log_buff = to_string(name, value, print_options)
499
480
  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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo