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

Methods inherited from Formatter

#close, #engine_running

Constructor Details

#initialize(filesystem) ⇒ JSONFormatter

Returns a new instance of JSONFormatter.



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

def initialize(filesystem)
  @filesystem = filesystem
  @has_begun = false
end

Instance Method Details

#failed(output) ⇒ Object



33
34
35
36
37
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 33

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

#finishedObject



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

def finished
  print "]\n"
end

#startedObject



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

def started
  print "["
end

#write(data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cc/analyzer/formatters/json_formatter.rb', line 19

def write(data)
  return unless data.present?

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

  if @has_begun
    print ",\n"
  end

  print document.to_json
  @has_begun = true
end