Module: Idxfence::Render

Defined in:
lib/idxfence/render.rb

Class Method Summary collapse

Class Method Details

.json(findings, warning: nil) ⇒ Object



24
25
26
# File 'lib/idxfence/render.rb', line 24

def json(findings, warning: nil)
  JSON.generate(findings: findings.map(&:to_h), warning: warning)
end

.text(findings, warning: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/idxfence/render.rb', line 7

def text(findings, warning: nil)
  lines = []
  lines << "idxfence: #{warning}" if warning

  if findings.empty?
    lines << "idxfence: no unguarded uniqueness validations found" unless warning
    return lines.join("\n")
  end

  lines << "idxfence: #{findings.size} finding(s)"
  findings.each do |f|
    scope_desc = f.scope.empty? ? "" : " (scope: #{f.scope.join(', ')})"
    lines << "[#{f.code}] #{f.file}:#{f.line} #{f.model}##{f.column}#{scope_desc} -> #{f.table} has no matching unique index: #{f.message}"
  end
  lines.join("\n")
end