Class: Undercover::JsonFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/undercover/json_formatter.rb

Instance Method Summary collapse

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_codeObject



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_hObject



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_sObject



13
14
15
# File 'lib/undercover/json_formatter.rb', line 13

def to_s
  JSON.pretty_generate(to_h)
end