Class: EasySeeds::Seeder

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_seeds/seeder.rb

Class Method Summary collapse

Class Method Details

.create_easy_seed_data(class_names) ⇒ Object

Creates easy seed data for all classes that are passed in



20
21
22
23
24
25
26
# File 'lib/easy_seeds/seeder.rb', line 20

def self.create_easy_seed_data(class_names)
  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

.single_seeder(table, class_name, table_string) ⇒ Object

Creates a single instance of seed data



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/easy_seeds/seeder.rb', line 7

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