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, 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]

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



50
51
52
53
54
55
56
# File 'lib/brakeman/report.rb', line 50

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

  generate(reporter)
end

#generate(reporter) ⇒ Object



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

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

#require_report(type) ⇒ Object



58
59
60
# File 'lib/brakeman/report.rb', line 58

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

#to_jsonObject



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

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

#to_markdownObject



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

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

#to_tableObject



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

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

#to_textObject Also known as: to_plain, to_s



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

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