Sha256: d75a8b62dd59e65c989f416ae0d0fff7ad5c7f9f12b074aa13f10e8c3664cd6f

Contents?: true

Size: 700 Bytes

Versions: 8

Compression:

Stored size: 700 Bytes

Contents

require 'csv'

module DataSeeder
  module Loader
    class CSV
      include Loader

      attr_reader :line_number

      def load(io)
        @line_number = 0
        csv = ::CSV.new(io, headers: true)
        csv.each do |row|
          begin
            @line_number += 1
            save(row.to_hash)
          rescue Exception => e
            # TODO: Consider counting the header in the line_number count, but anyone using
            # config[:use_line_number_as_id] would have all there id's incremented
            logger.error "Exception at line #{@line_number+1}: #{e.message}"
            raise unless config[:continue_on_exception]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
data_seeder-1.1.0 lib/data_seeder/loader/csv.rb
data_seeder-1.0.9 lib/data_seeder/loader/csv.rb
data_seeder-1.0.8 lib/data_seeder/loader/csv.rb
data_seeder-1.0.7 lib/data_seeder/loader/csv.rb
data_seeder-1.0.6 lib/data_seeder/loader/csv.rb
data_seeder-1.0.5 lib/data_seeder/loader/csv.rb
data_seeder-1.0.4 lib/data_seeder/loader/csv.rb
data_seeder-1.0.3 lib/data_seeder/loader/csv.rb