Class: Undercover::JsonFormatter
- Inherits:
-
Object
- Object
- Undercover::JsonFormatter
- Defined in:
- lib/undercover/json_formatter.rb
Instance Method Summary collapse
- #exit_code ⇒ Object
-
#initialize(results, validation_error = nil) ⇒ JsonFormatter
constructor
A new instance of JsonFormatter.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(results, validation_error = nil) ⇒ JsonFormatter
Returns a new instance of JsonFormatter.
8 9 10 11 |
# File 'lib/undercover/json_formatter.rb', line 8 def initialize(results, validation_error = nil) @results = results @validation_error = validation_error end |
Instance Method Details
#exit_code ⇒ Object
26 27 28 29 30 31 |
# File 'lib/undercover/json_formatter.rb', line 26 def exit_code return 0 if @validation_error return 0 unless @results.any? 1 end |
#to_h ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/undercover/json_formatter.rb', line 17 def to_h output = { warnings: warnings, summary: summary } output[:validation] = @validation_error.to_s if @validation_error && @validation_error != :no_changes output end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/undercover/json_formatter.rb', line 13 def to_s JSON.pretty_generate(to_h) end |