Class: Brakeman::Report

Inherits:
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, HTML, Hash, JSON, Markdown, Renderer, Table, Tabs

Constant Summary collapse

VALID_FORMATS =
[:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_hash, :to_s, :to_markdown]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_tree, tracker) ⇒ Report

Returns a new instance of Report.


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

def initialize app_tree, tracker
  @app_tree = app_tree
  @tracker = tracker
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object


45
46
47
48
49
50
51
# File 'lib/brakeman/report.rb', line 45

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

def format format
  reporter = case format
  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_s
    return self.to_s
  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


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

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

#require_report(type) ⇒ Object


53
54
55
# File 'lib/brakeman/report.rb', line 53

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

#to_jsonObject


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

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

#to_markdownObject


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

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

#to_sObject


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

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