Class: Migration::FromGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



13
14
15
16
# File 'lib/generators/migration/from_generator.rb', line 13

def next_migration_number(dirname) #:nodoc:
  next_migration_number = current_migration_number(dirname) + 1
  ActiveRecord::Migration.next_migration_number(next_migration_number)
end

Instance Method Details

#create_migrationsObject



30
31
32
33
34
35
36
# File 'lib/generators/migration/from_generator.rb', line 30

def create_migrations
  models.each do |current_model|
    @current_model = current_model
    migration_file_name = "#{migration_prefix}_#{current_model.name.underscore.gsub('/', '_').pluralize}"
    migration_template "migration_from_model.rb.erb", "db/migrate/#{migration_file_name}.rb"
  end
end

#preload_modelsObject



23
24
25
26
27
28
# File 'lib/generators/migration/from_generator.rb', line 23

def preload_models
  ActiveRecordSchema.autoload_paths.each do |p|
    load(p)
  end
  
end