Class: DynamicFieldMigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/dynamic_field_migration_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_migrationObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/dynamic_field_migration_generator.rb', line 11

def generate_migration
  destination = "db/migrate/dynamic_fields/#{next_migration_number}_#{file_name}.rb"
  
  @migration_file_name  = File.basename(destination).sub(".rb", "").split("_").slice(1..100).join('_')

  @migration_class_name = @migration_file_name.camelize

  migration_already_exists = self.class.migration_exists?("db/migrate/dynamic_fields/", @migration_file_name)
  template "#{migration_type}_field_migration.rb", destination unless self.class.migration_exists?("db/migrate/dynamic_fields/", @migration_file_name)
  `rake db:migrate_dynamic_fields` unless migration_already_exists

end