Module: CSVPlusPlus::Writer::FileBackerUpper

Included in:
CSV, Excel
Defined in:
lib/csv_plus_plus/writer/file_backer_upper.rb

Overview

A module that can be mixed into any Writer that needs to back up it’s @output_filename (all of them except Google Sheets)

Instance Method Summary collapse

Instance Method Details

#write_backupObject

Assuming the underlying spreadsheet is file-based, create a backup of it



14
15
16
17
18
19
20
21
22
# File 'lib/csv_plus_plus/writer/file_backer_upper.rb', line 14

def write_backup
  return unless ::File.exist?(@options.output_filename)

  # TODO: also don't do anything if the current backups contents haven't changed (do a md5sum or something)

  attempt_backups.tap do |backed_up_to|
    warn("Backed up #{@options.output_filename} to #{backed_up_to}") if @options.verbose
  end
end