Class: LogBuffer
- Inherits:
-
Object
- Object
- LogBuffer
- Defined in:
- lib/debugtrace/log_buffer.rb
Overview
Buffers logs.
Defined Under Namespace
Classes: LevelAndLog
Instance Method Summary collapse
-
#append(value, nest_level = 0, no_break = false) ⇒ Object
Appends a string representation of the value.
-
#append_buffer(separator, buff) ⇒ Object
Appends lines of another LogBuffer.
-
#down_nest ⇒ Object
Downs the data nest level.
-
#initialize(maximum_data_output_width) ⇒ LogBuffer
constructor
Initializes this object.
-
#length ⇒ Object
The length of the last line.
-
#line_feed ⇒ Object
Breaks the current line.
-
#lines ⇒ Object
A list of tuple of data indentation level && log string.
-
#multi_lines? ⇒ Boolean
true if multiple line, false otherwise.
-
#no_break_append(value) ⇒ Object
Appends a string representation of the value.
-
#up_nest ⇒ Object
Ups the data nest level.
Constructor Details
#initialize(maximum_data_output_width) ⇒ LogBuffer
Initializes this object.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/debugtrace/log_buffer.rb', line 23 def initialize(maximum_data_output_width) @maximum_data_output_width = Common.check_type('maximum_data_output_width', maximum_data_output_width, Integer) @nest_level = 0 @append_nest_level = 0 # tuples of data indentation level && log string @lines = [] # buffer for a line of logs @last_line = '' end |
Instance Method Details
#append(value, nest_level = 0, no_break = false) ⇒ Object
Appends a string representation of the value.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/debugtrace/log_buffer.rb', line 58 def append(value, nest_level = 0, no_break = false) Common.check_type('nest_level', nest_level, Integer) Common.check_type('no_break', no_break, TrueClass) unless value.nil? string = value.to_s line_feed if !no_break && length > 0 && length + string.length > @maximum_data_output_width @append_nest_level = nest_level @last_line += string end self end |
#append_buffer(separator, buff) ⇒ Object
Appends lines of another LogBuffer.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/debugtrace/log_buffer.rb', line 83 def append_buffer(separator, buff) Common.check_type('separator', separator, String) Common.check_type('buff', buff, LogBuffer) append(separator, 0, true) if separator != '' index = 0 for line in buff.lines line_feed if index > 0 append(line.log, line.nest_level, index == 0 && separator != '') index += 1 end self end |
#down_nest ⇒ Object
Downs the data nest level.
48 49 50 |
# File 'lib/debugtrace/log_buffer.rb', line 48 def down_nest @nest_level -= 1 end |
#length ⇒ Object
The length of the last line.
97 98 99 |
# File 'lib/debugtrace/log_buffer.rb', line 97 def length @last_line.length end |
#line_feed ⇒ Object
Breaks the current line.
36 37 38 39 40 |
# File 'lib/debugtrace/log_buffer.rb', line 36 def line_feed @lines << LevelAndLog.new(@nest_level + @append_nest_level, @last_line.rstrip) @append_nest_level = 0 @last_line = '' end |
#lines ⇒ Object
A list of tuple of data indentation level && log string.
107 108 109 110 111 |
# File 'lib/debugtrace/log_buffer.rb', line 107 def lines lines = @lines.dup lines << LevelAndLog.new(@nest_level, @last_line) if length > 0 lines end |
#multi_lines? ⇒ Boolean
true if multiple line, false otherwise.
102 103 104 |
# File 'lib/debugtrace/log_buffer.rb', line 102 def multi_lines? @lines.length > 1 || @lines.length == 1 && length > 0 end |
#no_break_append(value) ⇒ Object
Appends a string representation of the value. Does not break even if the maximum width is exceeded.
74 75 76 |
# File 'lib/debugtrace/log_buffer.rb', line 74 def no_break_append(value) append(value, 0, true) end |
#up_nest ⇒ Object
Ups the data nest level.
43 44 45 |
# File 'lib/debugtrace/log_buffer.rb', line 43 def up_nest @nest_level += 1 end |