class ActiveRecordImporter::FailedFileBuilder

Attributes

failed_rows[RW]
import[R]

Public Class Methods

new(import) click to toggle source
# File lib/active_record_importer/failed_file_builder.rb, line 6
def initialize(import)
  @import = import
end

Public Instance Methods

write(failed_row = {}) click to toggle source
# File lib/active_record_importer/failed_file_builder.rb, line 10
def write(failed_row = {})
  return if failed_row.blank?

  if File.exists?(temp_failed_file_path)
    File.open(temp_failed_file_path, 'a') do |file|
      file.write failed_row.values.to_csv
    end
  else
    File.open(temp_failed_file_path, 'w') do |file|
      file.write failed_row.keys
      file.write failed_row.values.to_csv
    end
  end
end

Private Instance Methods

target_file_name() click to toggle source
# File lib/active_record_importer/failed_file_builder.rb, line 31
def target_file_name
  "failed_file_#{import.id}.csv"
end
temp_failed_file_path() click to toggle source
# File lib/active_record_importer/failed_file_builder.rb, line 27
def temp_failed_file_path
  "/tmp/#{target_file_name}"
end