Class: Ruumba::Correctors::FileCorrector

Inherits:
Object
  • Object
show all
Includes:
Replacer
Defined in:
lib/ruumba/correctors.rb

Overview

Corrector for when normal file checking

Instance Method Summary collapse

Methods included from Replacer

#handle_corrected_output

Constructor Details

#initialize(digestor, parser) ⇒ FileCorrector

Returns a new instance of FileCorrector.



58
59
60
61
# File 'lib/ruumba/correctors.rb', line 58

def initialize(digestor, parser)
  @digestor = digestor
  @parser = parser
end

Instance Method Details

#correct(_stdout, _stderr, file_mappings) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ruumba/correctors.rb', line 63

def correct(_stdout, _stderr, file_mappings)
  file_mappings.each do |original_file, (ruumba_file, old_ruumba_digest, original_contents)|
    new_contents = File.read(ruumba_file)

    handle_corrected_output(old_ruumba_digest, new_contents, original_contents) do |corrected_output|
      File.open(original_file, 'w+') do |file_handle|
        file_handle.write(corrected_output)
      end
    end
  end
end