Class: WhyClasses::Formatters::DiffFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/why_classes/formatters/diff_formatter.rb

Overview

Shows a unified diff of the proposed rewrites (for --diff / --dry-run). Only files that actually changed are printed.

Defined Under Namespace

Modules: UnifiedDiff

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize

Constructor Details

This class inherits a constructor from WhyClasses::Formatters::BaseFormatter

Instance Method Details

#call(reports) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/why_classes/formatters/diff_formatter.rb', line 10

def call(reports)
  changed = reports.select(&:changed?)
  changed.each do |report|
    io.puts "--- #{report.path}"
    io.puts "+++ #{report.path}"
    io.print UnifiedDiff.render(report.original_source, report.corrected_source)
  end
  corrections = total_corrected(reports)
  io.puts "#{changed.size} file#{'s' unless changed.size == 1} would change, " \
          "#{corrections} correction#{'s' unless corrections == 1}."
end