Class: Yard::Lint::Executor::ResultCollector

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeResultCollector

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/yard/lint/executor/result_collector.rb', line 37

def empty?
  @lines.empty?
end

This method returns an undefined value.

Add multiple lines by splitting content on newlines. Each line is added separately to the output buffer.

Parameters:

  • content (String)

    multiline string to split and add



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

Parameters:

  • line (String, Object)

    content to add (will be converted to string)



17
18
19
# File 'lib/yard/lint/executor/result_collector.rb', line 17

def puts(line)
  @mutex.synchronize { @lines << line.to_s }
end

#sizeInteger

Get the number of lines collected

Returns:

  • (Integer)


43
44
45
# File 'lib/yard/lint/executor/result_collector.rb', line 43

def size
  @lines.size
end

#to_stdoutString

Get the collected output as a single string

Returns:

  • (String)

    all lines joined with newlines



31
32
33
# File 'lib/yard/lint/executor/result_collector.rb', line 31

def to_stdout
  @lines.join("\n")
end