Module: RailsCodeAuditor

Defined in:
lib/rails_code_auditor.rb,
lib/rails_code_auditor/scorer.rb,
lib/rails_code_auditor/grapher.rb,
lib/rails_code_auditor/version.rb,
lib/rails_code_auditor/analyzer.rb,
lib/rails_code_auditor/llm_client.rb,
lib/rails_code_auditor/pdf_generator.rb,
lib/rails_code_auditor/report_generator.rb,
lib/rails_code_auditor/simplecov_runner.rb,
lib/rails_code_auditor/html_to_pdf_converter.rb

Defined Under Namespace

Classes: Analyzer, Grapher, HtmlToPdfConverter, LlmClient, PdfGenerator, ReportGenerator, Scorer, SimpleCovRunner

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails_code_auditor.rb', line 15

def self.run(args)
  puts "[*] Running Rails Code Auditor..."

  # Parse CLI options
  use_llm     = args.include?("--use-llm")
  model_arg   = args[args.index("--llm-model") + 1] if args.include?("--llm-model")
  endpoint_arg = args[args.index("--llm-endpoint") + 1] if args.include?("--llm-endpoint")
  format_arg = args[args.index("--format") + 1] if args.include?("--format")
  output_arg = args[args.index("--output") + 1] if args.include?("--output")

  raw_results = Analyzer.run_all
  results = ReportGenerator.normalize(raw_results)
  results[:simplecov] = SimpleCovRunner.run
  scores = if use_llm
             LlmClient.score_with_llm(results, model: model_arg || "llama3",
                                               endpoint: endpoint_arg || "http://localhost:11434/api/generate") || Scorer.score(results)
           else
             Scorer.score(results)
           end

  if format_arg == "json"
    json_output = JSON.pretty_generate({ results: results, scores: scores })
    if output_arg
      File.write(output_arg, json_output)
      puts "[✓] JSON report saved to #{output_arg}"
    else
      puts json_output
    end
    return
  end
  graphs = Grapher.generate(scores)
  html_pdf_paths = USE_GROVER ? HtmlToPdfConverter.convert_all : []
  pdf_path = PdfGenerator.generate(results, scores, graphs, html_pdf_paths)
  if output_arg
    FileUtils.mv(pdf_path, output_arg)
    puts "[✓] PDF report saved to #{output_arg}"
  else
    puts "[✓] Audit complete. PDF report generated at #{pdf_path}"
  end
end