Holds common methods for migrations. It assumes that migrations has the [0-9]*_name format and can be used by another frameworks (like Sequel) just by implementing the next migration version method.

Methods
M
Classes and Modules
Attributes
[R] migration_number
[R] migration_file_name
[R] migration_class_name
Instance Public methods
migration_template(source, destination=nil, config={})

Creates a migration template at the given destination. The difference to the default template method is that the migration version is appended to the destination file name.

The migration version, migration file name, migration class name are available as instance variables in the template to be rendered.

Examples

  migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
    # File railties/lib/rails/generators/migration.rb, line 45
45:       def migration_template(source, destination=nil, config={})
46:         destination = File.expand_path(destination || source, self.destination_root)
47: 
48:         migration_dir = File.dirname(destination)
49:         @migration_number     = self.class.next_migration_number(migration_dir)
50:         @migration_file_name  = File.basename(destination).sub(/\.rb$/, '')
51:         @migration_class_name = @migration_file_name.camelize
52: 
53:         destination = self.class.migration_exists?(migration_dir, @migration_file_name)
54: 
55:         if !(destination && options[:skip]) && behavior == :invoke
56:           if destination && options.force?
57:             remove_file(destination)
58:           elsif destination
59:             raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
60:           end
61:           destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
62:         end
63: 
64:         template(source, destination, config)
65:       end