2011-02-09 05:52:43 -05:00
|
|
|
require 'rails/generators'
|
|
|
|
require 'rails/generators/migration'
|
2013-08-19 12:02:11 -04:00
|
|
|
require 'rails/generators/active_record'
|
2011-02-09 05:52:43 -05:00
|
|
|
|
|
|
|
module PaperTrail
|
2013-08-19 09:44:08 -04:00
|
|
|
class InstallGenerator < ::Rails::Generators::Base
|
|
|
|
include ::Rails::Generators::Migration
|
2011-02-09 05:52:43 -05:00
|
|
|
|
|
|
|
source_root File.expand_path('../templates', __FILE__)
|
2011-07-13 04:56:04 -04:00
|
|
|
class_option :with_changes, :type => :boolean, :default => false, :desc => "Store changeset (diff) with each version"
|
2011-02-09 05:52:43 -05:00
|
|
|
|
|
|
|
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'
|
2011-07-12 13:08:58 -04:00
|
|
|
migration_template 'add_object_changes_column_to_versions.rb', 'db/migrate/add_object_changes_column_to_versions.rb' if options.with_changes?
|
2011-02-09 05:52:43 -05:00
|
|
|
end
|
2013-02-04 19:31:05 -05:00
|
|
|
|
|
|
|
def self.next_migration_number(dirname)
|
2013-10-16 15:35:53 -04:00
|
|
|
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
2013-02-04 19:31:05 -05:00
|
|
|
end
|
2011-02-09 05:52:43 -05:00
|
|
|
end
|
|
|
|
end
|