Class: Screamers::Generators::MigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/screamers/migration/migration_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



12
13
14
# File 'lib/rails/generators/screamers/migration/migration_generator.rb', line 12

def self.source_root
  File.expand_path('../templates', __FILE__)
end

Instance Method Details

#create_migration_fileObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails/generators/screamers/migration/migration_generator.rb', line 16

def create_migration_file
  collector = Screamers::SchemaCollector.new(old_column_type, new_column_type)

  @target_columns = collector.collect_schema

  if @target_columns.empty?
    puts '[Screamers] There is no change in the schema.'; exit!
  end

  file_name = "#{Time.current.strftime('%Y%m%d%H%M%S')}_change_#{old_column_type}_to_#{new_column_type}_using_screamers"

  template 'migration.rb.tt', File.join('db/migrate', "#{file_name}.rb")
end