lib/generators/draftsman/install_generator.rb in draftsman-0.2.1 vs lib/generators/draftsman/install_generator.rb in draftsman-0.3.0
- old
+ new
@@ -4,17 +4,31 @@
module Draftsman
class InstallGenerator < ::Rails::Generators::Base
include ::Rails::Generators::Migration
- desc 'Generates (but does not run) a migration to add a drafts table.'
+ desc 'Creates config initializer and generates (but does not run) a migration to add a drafts table.'
source_root File.expand_path('../templates', __FILE__)
class_option :skip_initializer, :type => :boolean, :default => false, :desc => 'Skip generation of the boilerplate initializer at `config/initializers/draftsman.rb`.'
- class_option :with_changes, :type => :boolean, :default => false, :desc => 'Store changeset (diff) with each draft'
+ class_option :with_changes, :type => :boolean, :default => false, :desc => 'Store changeset (diff) with each draft.'
+ class_option :with_pg_json, :type => :boolean, :default => false, :desc => 'Use PostgreSQL JSON data type for serialized data.'
def create_migration_file
- migration_template 'create_drafts.rb', 'db/migrate/create_drafts.rb'
- migration_template 'add_object_changes_column_to_drafts.rb', 'db/migrate/add_object_changes_column_to_drafts.rb' if options.with_changes?
+ if options.with_pg_json?
+ migration_template 'create_drafts_json.rb', 'db/migrate/create_drafts.rb'
+
+ if options.with_changes?
+ migration_template 'add_object_changes_column_to_drafts_json.rb',
+ 'db/migrate/add_object_changes_column_to_drafts.rb'
+ end
+ else
+ migration_template 'create_drafts.rb', 'db/migrate/create_drafts.rb'
+
+ if options.with_changes?
+ migration_template 'add_object_changes_column_to_drafts.rb',
+ 'db/migrate/add_object_changes_column_to_drafts.rb'
+ end
+ end
end
def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end