Class: Yard::Lint::Executor::ResultCollector
- Inherits:
-
Object
- Object
- Yard::Lint::Executor::ResultCollector
- Defined in:
- lib/yard/lint/executor/result_collector.rb
Overview
Collects query output in a format matching shell stdout. Used by validators to write their results during in-process execution.
Instance Method Summary collapse
-
#clear! ⇒ void
Clear all collected output.
-
#empty? ⇒ Boolean
Check if any output has been collected.
-
#initialize ⇒ ResultCollector
constructor
A new instance of ResultCollector.
-
#print(content) ⇒ void
Add multiple lines by splitting content on newlines.
-
#puts(line) ⇒ void
Add a single line to the output.
-
#size ⇒ Integer
Get the number of lines collected.
-
#to_stdout ⇒ String
Get the collected output as a single string.
Constructor Details
#initialize ⇒ ResultCollector
Returns a new instance of ResultCollector.
9 10 11 12 |
# File 'lib/yard/lint/executor/result_collector.rb', line 9 def initialize @lines = [] @mutex = Mutex.new end |
Instance Method Details
#clear! ⇒ void
This method returns an undefined value.
Clear all collected output
49 50 51 |
# File 'lib/yard/lint/executor/result_collector.rb', line 49 def clear! @mutex.synchronize { @lines.clear } end |
#empty? ⇒ Boolean
Check if any output has been collected
37 38 39 |
# File 'lib/yard/lint/executor/result_collector.rb', line 37 def empty? @lines.empty? end |
#print(content) ⇒ void
This method returns an undefined value.
Add multiple lines by splitting content on newlines. Each line is added separately to the output buffer.
25 26 27 |
# File 'lib/yard/lint/executor/result_collector.rb', line 25 def print(content) content.to_s.each_line { |line| puts(line.chomp) } end |
#puts(line) ⇒ void
This method returns an undefined value.
Add a single line to the output
17 18 19 |
# File 'lib/yard/lint/executor/result_collector.rb', line 17 def puts(line) @mutex.synchronize { @lines << line.to_s } end |
#size ⇒ Integer
Get the number of lines collected
43 44 45 |
# File 'lib/yard/lint/executor/result_collector.rb', line 43 def size @lines.size end |
#to_stdout ⇒ String
Get the collected output as a single string
31 32 33 |
# File 'lib/yard/lint/executor/result_collector.rb', line 31 def to_stdout @lines.join("\n") end |