Class: Planter::Generators::SeederGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/planter/seeder_generator.rb

Overview

Rails generator that creates one or more Planter seeder files.

By default, generated seeders include a TODO comment and an empty seed method so they do not raise until a seeding method is chosen. Pass --seeding-method=csv, --seeding-method=data-array, or --seeding-method=custom to generate a seeder for a specific style. The csv method also creates a CSV seed file with headers pulled from the table being seeded.

Constant Summary collapse

SEEDING_METHODS =

Generator-supported seeding method templates.

Returns:

  • (Array<Symbol>)
%i[csv data_array custom].freeze

Instance Method Summary collapse

Instance Method Details

#generate_seedersObject

Generate the requested seeder, or generate a seeder for every table when the argument is ALL.



32
33
34
# File 'lib/generators/planter/seeder_generator.rb', line 32

def generate_seeders
  (seeder == "ALL") ? tables.each { |t| generate(t) } : generate(seeder)
end