Class: CC::Analyzer::Formatters::JSONFormatter

Inherits:
Formatter
  • Object
show all
Defined in:
lib/cc/analyzer/formatters/json_formatter.rb

Constant Summary

Constants inherited from Formatter

Formatter::InvalidFormatterError

Instance Method Summary collapse

Constructor Details

#initializeJSONFormatter

Returns a new instance of JSONFormatter.



6
7
8
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 6

def initialize
  @has_begun = false
end

Instance Method Details

#engine_running(engine) ⇒ Object



10
11
12
13
14
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 10

def engine_running(engine)
  @active_engine = engine
  yield
  @active_engine = nil
end

#failed(output) ⇒ Object



38
39
40
41
42
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 38

def failed(output)
  $stderr.puts "\nAnalysis failed with the following output:"
  $stderr.puts output
  exit 1
end

#finishedObject



20
21
22
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 20

def finished
  print " ]\n"
end

#startedObject



16
17
18
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 16

def started
  print "[ "
end

#write(data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 24

def write(data)
  return unless data.present?

  document = JSON.parse(data)
  document["engine_name"] = @active_engine.name

  if @has_begun
    print ",\n"
  end

  print document.to_json
  @has_begun = true
end