module Rails::Generators::Migration
def create_migration(destination, data, config = {}, &block)
def create_migration(destination, data, config = {}, &block) action Rails::Generators::Actions::CreateMigration.new(self, destination, block || data.to_s, config) end
def migration_template(source, destination, config = {})
available as instance variables in the template to be rendered.
The migration number, migration file name, migration class name are
to the destination file name.
to the default template method is that the migration number is prepended
Creates a migration template at the given destination. The difference
def migration_template(source, destination, config = {}) source = File.expand_path(find_in_source_paths(source.to_s)) set_migration_assigns!(destination) dir, base = File.split(destination) numbered_destination = File.join(dir, ["%migration_number%", base].join("_")) file = create_migration numbered_destination, nil, config do ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(binding) end Rails::Generators.add_generated_file(file) end
def set_migration_assigns!(destination)
def set_migration_assigns!(destination) destination = File.expand_path(destination, destination_root) migration_dir = File.dirname(destination) @migration_number = self.class.next_migration_number(migration_dir) @migration_file_name = File.basename(destination, ".rb") @migration_class_name = @migration_file_name.camelize end