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) ⇒ LogBuffer
Appends a string representation of the value.
-
#append_buffer(buff) ⇒ LogBuffer
Appends lines of another LogBuffer.
-
#down_nest ⇒ Object
Downs the data nest level.
-
#initialize(data_output_width) ⇒ LogBuffer
constructor
Initializes this object.
-
#length ⇒ Object
The length of the last line.
-
#line_feed ⇒ Object
Breaks the current line.
-
#lines ⇒ Array<LevelAndLog>
Returns the LevelAndLog objects.
-
#multi_lines? ⇒ FalseClass, TrueClass
Returns true if multiple line, false otherwise.
-
#no_break_append(value) ⇒ LogBuffer
Appends a string representation of the value.
-
#up_nest ⇒ Object
Ups the data nest level.
Constructor Details
#initialize(data_output_width) ⇒ LogBuffer
Initializes this object.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/debugtrace/log_buffer.rb', line 30 def initialize(data_output_width) @data_output_width = Common.check_type('data_output_width', 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) ⇒ LogBuffer
Appends a string representation of the value.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/debugtrace/log_buffer.rb', line 66 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 > @data_output_width @append_nest_level = nest_level @last_line += string end return self end |
#append_buffer(buff) ⇒ LogBuffer
Appends lines of another LogBuffer.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/debugtrace/log_buffer.rb', line 91 def append_buffer(buff) Common.check_type('buff', buff, LogBuffer) index = 0 for line in buff.lines line_feed if index > 0 append(line.log, line.nest_level) index += 1 end return self end |
#down_nest ⇒ Object
Downs the data nest level.
55 56 57 |
# File 'lib/debugtrace/log_buffer.rb', line 55 def down_nest @nest_level -= 1 end |
#length ⇒ Object
The length of the last line.
103 104 105 |
# File 'lib/debugtrace/log_buffer.rb', line 103 def length return @last_line.length end |
#line_feed ⇒ Object
Breaks the current line.
43 44 45 46 47 |
# File 'lib/debugtrace/log_buffer.rb', line 43 def line_feed @lines << LevelAndLog.new(@nest_level + @append_nest_level, @last_line.rstrip) @append_nest_level = 0 @last_line = '' end |
#lines ⇒ Array<LevelAndLog>
Returns the LevelAndLog objects.
117 118 119 120 121 |
# File 'lib/debugtrace/log_buffer.rb', line 117 def lines lines = @lines.dup lines << LevelAndLog.new(@nest_level, @last_line) if length > 0 return lines end |
#multi_lines? ⇒ FalseClass, TrueClass
Returns true if multiple line, false otherwise.
110 111 112 |
# File 'lib/debugtrace/log_buffer.rb', line 110 def multi_lines? return @lines.length > 1 || @lines.length == 1 && length > 0 end |
#no_break_append(value) ⇒ LogBuffer
Appends a string representation of the value. Does not break even if the maximum width is exceeded.
83 84 85 |
# File 'lib/debugtrace/log_buffer.rb', line 83 def no_break_append(value) return append(value, 0, true) end |
#up_nest ⇒ Object
Ups the data nest level.
50 51 52 |
# File 'lib/debugtrace/log_buffer.rb', line 50 def up_nest @nest_level += 1 end |