lib/attractor/reporters/console_reporter.rb in attractor-2.4.0 vs lib/attractor/reporters/console_reporter.rb in attractor-2.5.0
- old
+ new
@@ -47,16 +47,43 @@
puts result
end
end
+ class JSONFormatter
+ def call(calculators)
+ result = calculators.map do |calc|
+ type = calc.last.type
+ values = calc.last.calculate
+ suggester = Suggester.new(values)
+ to_be_refactored = suggester.suggest.map(&:file_path)
+
+ [
+ type, values.map do |value|
+ {
+ file_path: value.file_path,
+ score: value.score,
+ complexity: value.complexity,
+ churn: value.churn,
+ refactor: to_be_refactored.include?(value.file_path)
+ }
+ end
+ ]
+ end
+
+ puts result.to_h.to_json
+ end
+ end
+
def initialize(format:, **other)
super(**other)
@formatter = case format.to_sym
- when :csv
- CSVFormatter.new
- else
- TableFormatter.new
+ when :csv
+ CSVFormatter.new
+ when :json
+ JSONFormatter.new
+ else
+ TableFormatter.new
end
end
def report
super