Class: Bulletproof::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/bulletproof/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



9
10
11
# File 'lib/bulletproof/report.rb', line 9

def initialize
  @violations = []
end

Instance Attribute Details

#violationsObject (readonly)

Returns the value of attribute violations.



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

def violations
  @violations
end

Instance Method Details

#add_violation(violation) ⇒ Object



13
14
15
16
# File 'lib/bulletproof/report.rb', line 13

def add_violation(violation)
  @violations << violation
  self
end

#ok?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bulletproof/report.rb', line 18

def ok?
  @violations.empty?
end

#to_sObject



22
23
24
25
26
27
28
# File 'lib/bulletproof/report.rb', line 22

def to_s
  return "No violations found." if ok?

  @violations.map do |v|
    "[#{v.severity.upcase}] #{v.file}:#{v.line} — #{v.message}"
  end.join("\n")
end