Make Generator more Rails 3-esque.

This commit is contained in:
Andy Stewart 2011-02-09 10:52:43 +00:00
parent 36a4b9b323
commit a535ed4f22
3 changed files with 19 additions and 25 deletions

View File

@ -494,7 +494,7 @@ Over time your `versions` table will grow to an unwieldy size. Because each ver
2. Generate a migration which will add a `versions` table to your database.
`rails generate paper_trail`
`rails generate paper_trail:install`
3. Run the migration.

View File

@ -0,0 +1,18 @@
require 'rails/generators'
require 'rails/generators/migration'
require 'rails/generators/active_record/migration'
module PaperTrail
class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
extend ActiveRecord::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
desc 'Generates (but does not run) a migration to add a versions table.'
def create_migration_file
migration_template 'create_versions.rb', 'db/migrate/create_versions.rb'
end
end
end

View File

@ -1,24 +0,0 @@
require 'rails/generators/named_base'
require 'rails/generators/migration'
class PaperTrailGenerator < Rails::Generators::NamedBase
include Rails::Generators::Migration
desc "Generates (but does not run) a migration to add a versions table."
source_root File.expand_path('../templates', __FILE__)
argument :name, :type => :string, :default => "create_versions"
# Implement the required interface for Rails::Generators::Migration.
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end
def create_migration_file
migration_template 'create_versions.rb', 'db/migrate/create_versions.rb'
end
end