Class: Stormbreaker::ErbFormatter
- Inherits:
-
Object
- Object
- Stormbreaker::ErbFormatter
- Includes:
- ERB::Util
- Defined in:
- lib/stormbreaker/erb_formatter.rb
Instance Attribute Summary collapse
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#initialize(violations) ⇒ ErbFormatter
constructor
A new instance of ErbFormatter.
- #parse_callstack(violation) ⇒ Object
- #sort_violations(violations) ⇒ Object
- #template ⇒ Object
- #total_violations ⇒ Object
- #write_to_erb ⇒ Object
Constructor Details
#initialize(violations) ⇒ ErbFormatter
Returns a new instance of ErbFormatter.
10 11 12 13 |
# File 'lib/stormbreaker/erb_formatter.rb', line 10 def initialize(violations) @violations = sort_violations(violations) @severity_categories = Stormbreaker.configuration.enabled_severity_categories end |
Instance Attribute Details
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
8 9 10 |
# File 'lib/stormbreaker/erb_formatter.rb', line 8 def violations @violations end |
Instance Method Details
#parse_callstack(violation) ⇒ Object
33 34 35 36 37 |
# File 'lib/stormbreaker/erb_formatter.rb', line 33 def parse_callstack(violation) return if violation.called_by.to_a.empty? violation.called_by.to_a.map { |spec| " #{spec}" }.join("\n") end |
#sort_violations(violations) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/stormbreaker/erb_formatter.rb', line 15 def sort_violations(violations) sorted = {} Stormbreaker.configuration.enabled_severity_categories.each do |severity| sorted[severity] = violations.select { |v| v.severity == severity } end sorted end |
#template ⇒ Object
39 40 41 |
# File 'lib/stormbreaker/erb_formatter.rb', line 39 def template File.read(File.join(File.dirname(__FILE__), "../templates/results.erb")) end |
#total_violations ⇒ Object
29 30 31 |
# File 'lib/stormbreaker/erb_formatter.rb', line 29 def total_violations @violations.reduce(0) { |key, (_category, violations)| key + violations.count } end |
#write_to_erb ⇒ Object
23 24 25 26 27 |
# File 'lib/stormbreaker/erb_formatter.rb', line 23 def write_to_erb erb = ERB.new(template) File.write(Stormbreaker.configuration.results_path, erb.result(binding)) puts "Results written to #{Stormbreaker.configuration.results_path}" end |