Add install generator for migration and default model

master
Guillaume DOTT 2013-11-26 14:18:40 +01:00
parent c3c4962d18
commit fc72e412bc
4 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,8 @@
Description:
Explain the generator
Example:
rails generate install Thing
This will create:
what/will/it/create

View File

@ -0,0 +1,18 @@
class TheModerator::InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def copy_model
template 'moderation.rb', File.join('app', 'models', 'moderation.rb')
end
def create_migration
migration_template 'migration.rb', 'db/migrate/create_moderations.rb'
end
def self.next_migration_number(dirname)
ActiveRecord::Migration.next_migration_number(
current_migration_number(dirname) + 1)
end
end

View File

@ -0,0 +1,14 @@
class CreateModerations < ActiveRecord::Migration
def self.up
create_table "moderations" do |t|
t.references :moderatable, polymorphic: true
t.text :data, :null => false
t.timestamps
end
end
def self.down
drop_table :moderations
end
end

View File

@ -0,0 +1,3 @@
class Moderation < ActiveRecord::Base
include TheModerator::ModerationModel
end