lib/pg_csv.rb in pg_csv-0.1.5 vs lib/pg_csv.rb in pg_csv-0.1.6

- old
+ new

@@ -83,11 +83,11 @@ method(:export_to_stream).to_proc end def export_to_stream(stream) count = write_csv(stream) - stream.flush if stream.respond_to?(:flush) + stream.flush if stream.respond_to?(:flush) && count > 0 info "<= done exporting (#{count}) records." end def write_csv(stream) @@ -194,14 +194,13 @@ include Base def self.with_temp_file(dest, tmp_dir = '/tmp', &block) require 'fileutils' - require 'tempfile' - - tempfile = Tempfile.new("pg_csv", tmp_dir) - yield(tempfile.path) - - FileUtils.mv(tempfile.path, dest) + + filename = File.join(tmp_dir, "pg_csv_#{Time.now.to_f}_#{rand(1000000)}") + block[filename] + + FileUtils.mv(filename, dest) end -end \ No newline at end of file +end