Module: Capistrano::Doctor::OutputHelpers

Included in:
EnvironmentDoctor, GemsDoctor, ServersDoctor, VariablesDoctor
Defined in:
lib/capistrano/doctor/output_helpers.rb

Overview

Helper methods for pretty-printing doctor output to stdout. All output (other than ‘title`) is indented by four spaces to facilitate copying and pasting this output into e.g. GitHub or Stack Overflow to achieve code formatting.

Defined Under Namespace

Classes: Row

Instance Method Summary collapse

Instance Method Details

#puts(string = nil) ⇒ Object

Override ‘Kernel#puts` to prepend four spaces to each line.



55
56
57
# File 'lib/capistrano/doctor/output_helpers.rb', line 55

def puts(string=nil)
  $stdout.puts(string.to_s.gsub(/^/, "    "))
end

#table(records, &block) ⇒ Object

Prints a table for a given array of records. For each record, the block is yielded two arguments: the record and a Row object. To print values for that record, add values using ‘row << “some value”`. A row can optionally be highlighted in yellow using `row.yellow`.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/capistrano/doctor/output_helpers.rb', line 29

def table(records, &block)
  return if records.empty?
  rows = collect_rows(records, &block)
  col_widths = calculate_column_widths(rows)

  rows.each do |row|
    line = row.values.each_with_index.map do |value, col|
      value.to_s.ljust(col_widths[col])
    end.join(" ").rstrip
    line = color.colorize(line, row.color) if row.color
    puts line
  end
end

#title(text) ⇒ Object

Prints a title in blue with surrounding newlines.



44
45
46
47
# File 'lib/capistrano/doctor/output_helpers.rb', line 44

def title(text)
  # Use $stdout directly to bypass the indentation that our `puts` does.
  $stdout.puts(color.colorize("\n#{text}\n", :blue))
end

#warning(text) ⇒ Object

Prints text in yellow.



50
51
52
# File 'lib/capistrano/doctor/output_helpers.rb', line 50

def warning(text)
  puts color.colorize(text, :yellow)
end