Class: CC::Analyzer::Formatters::Formatter

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

Direct Known Subclasses

HTMLFormatter, JSONFormatter, PlainTextFormatter

Constant Summary collapse

InvalidFormatterError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(filesystem, output = $stdout) ⇒ Formatter

Returns a new instance of Formatter.



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

def initialize(filesystem, output = $stdout)
  @filesystem = filesystem
  @output = output
end

Instance Method Details

#closeObject



39
40
# File 'lib/cc/analyzer/formatters/formatter.rb', line 39

def close
end

#engine_running(engine) ⇒ Object



29
30
31
32
33
34
# File 'lib/cc/analyzer/formatters/formatter.rb', line 29

def engine_running(engine)
  @current_engine = engine
  yield
ensure
  @current_engine = nil
end

#failed(_output) ⇒ Object



42
43
# File 'lib/cc/analyzer/formatters/formatter.rb', line 42

def failed(_output)
end

#finishedObject



36
37
# File 'lib/cc/analyzer/formatters/formatter.rb', line 36

def finished
end

#startedObject



26
27
# File 'lib/cc/analyzer/formatters/formatter.rb', line 26

def started
end

#write(data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cc/analyzer/formatters/formatter.rb', line 10

def write(data)
  json = JSON.parse(data)
  json["engine_name"] = current_engine.name

  case json["type"].downcase
  when "issue"
    issues << json
  when "warning"
    warnings << json
  when "measurement"
    measurements << json
  else
    raise "Invalid type found: #{json["type"]}"
  end
end