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, HTML, Hash, JSON, JUnit, Markdown, Renderer, 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]

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


53
54
55
56
57
58
59
# File 'lib/brakeman/report.rb', line 53

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
# 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
  else
    raise "Invalid format: #{format}. Should be one of #{VALID_FORMATS.inspect}"
  end

  generate(reporter)
end

#generate(reporter) ⇒ Object


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

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

#require_report(type) ⇒ Object


61
62
63
# File 'lib/brakeman/report.rb', line 61

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

#to_jsonObject


65
66
67
68
# File 'lib/brakeman/report.rb', line 65

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

#to_markdownObject


75
76
77
78
# File 'lib/brakeman/report.rb', line 75

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

#to_tableObject


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

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

#to_textObject Also known as: to_plain, to_s


80
81
82
83
# File 'lib/brakeman/report.rb', line 80

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