class RuboCop::ResultCache

def save(offenses, disabled_line_ranges, comments)

def save(offenses, disabled_line_ranges, comments)
  FileUtils.mkdir_p(File.dirname(@path))
  preliminary_path = "#{@path}_#{rand(1_000_000_000)}"
  File.open(preliminary_path, 'wb') do |f|
    # The Hash[x.sort] call is a trick that converts a Hash with a default
    # block to a Hash without a default block. Thus making it possible to
    # dump.
    f.write(Marshal.dump([offenses, Hash[disabled_line_ranges.sort],
                          comments]))
  end
  # The preliminary path is used so that if there are multiple RuboCop
  # processes trying to save data for the same inspected file
  # simultaneously, the only problem we run in to is a competition who gets
  # to write to the final file. The contents are the same, so no corruption
  # of data should occur.
  FileUtils.mv(preliminary_path, @path)
end