Sha256: 494b615c5d47ecd981fb038f867783cc5181d8d69d5a4a8c78057d5774b016e8

Contents?: true

Size: 956 Bytes

Versions: 1

Compression:

Stored size: 956 Bytes

Contents

require_relative './csv_methods'

module EasySeeds 
  class Seeder
    
    #Creates a single instance of seed data
    def self.single_seeder(table, class_name, table_string)
      ApplicationRecord.connection.reset_pk_sequence!(table_string)
      puts "Creating #{table_string} seed data..."
      
      table.each_with_index do |row, i| 
        puts "Finished Seeding the #{i.to_s}th #{table_string} item" if i % 100 == 0
        class_name.create!(**row)
      end
      
      puts "DONE WITH #{table_string.upcase}, #{table_string.upcase} SEEDING SUCCESSFUL"
    end 
    
    #Creates easy seed data for all classes that are passed in
    def self.create_easy_seed_data(class_names)
      puts 'Creating easy seeds data'
      tables, table_strings = EasySeeds::CSVLoader.tables_from_csvs
      
      (0...tables.length).each do |i|
        EasySeeds::Seeder.single_seeder(tables[i], class_names[i], table_strings[i])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy_seeds-1.0.6 lib/easy_seeds/seeder.rb