Class: Brakeman::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/brakeman/report.rb,
lib/brakeman/report/renderer.rb

Overview

Generates a report based on the Tracker and the results of Tracker#run_checks. Be sure to run_checks before generating a report.

Defined Under Namespace

Classes: Base, CSV, CodeClimate, Github, HTML, Hash, JSON, JUnit, Markdown, Renderer, SARIF, Sonar, Table, Tabs, Text

Constant Summary collapse

VALID_FORMATS =
[:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_hash, :to_s, :to_markdown, :to_codeclimate, :to_plain, :to_text, :to_junit, :to_github]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracker) ⇒ Report

Returns a new instance of Report.



11
12
13
14
# File 'lib/brakeman/report.rb', line 11

def initialize tracker
  @app_tree = tracker.app_tree
  @tracker = tracker
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/brakeman/report.rb', line 61

def method_missing method, *args
  if VALID_FORMATS.include? method
    format method
  else
    super
  end
end

Instance Attribute Details

#trackerObject (readonly)

Returns the value of attribute tracker.



7
8
9
# File 'lib/brakeman/report.rb', line 7

def tracker
  @tracker
end

Instance Method Details

#format(format) ⇒ Object



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
55
56
57
58
59
# File 'lib/brakeman/report.rb', line 16

def format format
  reporter = case format
  when :to_codeclimate
    require_report 'codeclimate'
    Brakeman::Report::CodeClimate
  when :to_csv
    require_report 'csv'
    Brakeman::Report::CSV
  when :to_html
    require_report 'html'
    Brakeman::Report::HTML
  when :to_json
    return self.to_json
  when :to_tabs
    require_report 'tabs'
    Brakeman::Report::Tabs
  when :to_hash
    require_report 'hash'
    Brakeman::Report::Hash
  when :to_markdown
    return self.to_markdown
  when :to_plain, :to_text, :to_s
    return self.to_plain
  when :to_table
    return self.to_table
  when :to_pdf
    raise "PDF output is not yet supported."
  when :to_junit
    require_report 'junit'
    Brakeman::Report::JUnit
  when :to_sarif
    return self.to_sarif
  when :to_sonar
    require_report 'sonar'
    Brakeman::Report::Sonar
  when :to_github
    require_report 'github'
    Brakeman::Report::Github
  else
    raise "Invalid format: #{format}. Should be one of #{VALID_FORMATS.inspect}"
  end

  generate(reporter)
end

#generate(reporter) ⇒ Object



106
107
108
# File 'lib/brakeman/report.rb', line 106

def generate reporter
  reporter.new(@tracker).generate_report
end

#require_report(type) ⇒ Object



69
70
71
# File 'lib/brakeman/report.rb', line 69

def require_report type
  require "brakeman/report/report_#{type}"
end

#to_jsonObject



73
74
75
76
# File 'lib/brakeman/report.rb', line 73

def to_json
  require_report 'json'
  generate Brakeman::Report::JSON
end

#to_markdownObject



88
89
90
91
# File 'lib/brakeman/report.rb', line 88

def to_markdown
  require_report 'markdown'
  generate Brakeman::Report::Markdown
end

#to_sarifObject



101
102
103
104
# File 'lib/brakeman/report.rb', line 101

def to_sarif
  require_report 'sarif'
  generate Brakeman::Report::SARIF
end

#to_sonarObject



78
79
80
81
# File 'lib/brakeman/report.rb', line 78

def to_sonar
  require_report 'sonar'
  generate Brakeman::Report::Sonar
end

#to_tableObject



83
84
85
86
# File 'lib/brakeman/report.rb', line 83

def to_table
  require_report 'table'
  generate Brakeman::Report::Table
end

#to_textObject Also known as: to_plain, to_s



93
94
95
96
# File 'lib/brakeman/report.rb', line 93

def to_text
  require_report 'text'
  generate Brakeman::Report::Text
end