class Railroader::Report::Markdown

Public Class Methods

new(*args) click to toggle source
Calls superclass method Railroader::Report::Table::new
# File lib/railroader/report/report_markdown.rb, line 24
def initialize *args
  super
  @table = MarkdownTable
end

Public Instance Methods

convert_warning(warning, original) click to toggle source
# File lib/railroader/report/report_markdown.rb, line 86
def convert_warning warning, original
  warning["Confidence"] = TEXT_CONFIDENCE[warning["Confidence"]]
  warning["Message"] = markdown_message original, warning["Message"]
  warning["Warning Type"] = "[#{warning['Warning Type']}](#{original.link})" if original.link
  warning
end
generate_checks() click to toggle source
# File lib/railroader/report/report_markdown.rb, line 80
def generate_checks
  MarkdownTable.new(:headings => ['Checks performed']) do |t|
    t.add_row([checks.checks_run.sort.join(", ")])
  end
end
generate_metadata() click to toggle source
# File lib/railroader/report/report_markdown.rb, line 65
def generate_metadata
  MarkdownTable.new(
    :headings =>
      ['Application path', 'Rails version', 'Railroader version', 'Started at', 'Duration']
  ) do |t|
    t.add_row([
      tracker.app_path,
      rails_version,
      Railroader::Version,
      tracker.start_time,
      "#{tracker.duration} seconds",
    ])
  end
end
generate_report() click to toggle source
# File lib/railroader/report/report_markdown.rb, line 29
def generate_report
  out = "# BRAKEMAN REPORT\n\n" <<
  generate_metadata.to_s << "\n\n" <<
  generate_checks.to_s << "\n\n" <<
  "### SUMMARY\n\n" <<
  generate_overview.to_s << "\n\n" <<
  generate_warning_overview.to_s << "\n\n"

  # Return output early if only summarizing
  return out if tracker.options[:summary_only]

  if tracker.options[:report_routes] or tracker.options[:debug]
    out << "### CONTROLLERS"  << "\n\n" <<
    generate_controllers.to_s << "\n\n"
  end

  if tracker.options[:debug]
    out << "### TEMPLATES\n\n" <<
    generate_templates.to_s << "\n\n"
  end

  output_table("Errors", generate_errors, out)
  output_table("SECURITY WARNINGS", generate_warnings, out)
  output_table("Controller Warnings:", generate_controller_warnings, out)
  output_table("Model Warnings:", generate_model_warnings, out)
  output_table("View Warnings:", generate_template_warnings, out)

  out
end
markdown_message(warning, message) click to toggle source

Escape and code format warning message

# File lib/railroader/report/report_markdown.rb, line 94
def markdown_message warning, message
  if warning.file
    github_url = github_url warning.file, warning.line
    message.gsub!(/(near line \d+)/, "[\\1](#{github_url})") if github_url
  end
  if warning.code
    code = warning.format_code
    message.gsub(code, "`#{code.gsub('`', '``').gsub(/\A``|``\z/, '` `')}`")
  else
    message
  end
end
output_table(title, result, output) click to toggle source
# File lib/railroader/report/report_markdown.rb, line 59
def output_table title, result, output
  return unless result

  output << "### #{title}\n\n#{result.to_s}\n\n"
end