Add install generator for migration and default model
parent
c3c4962d18
commit
fc72e412bc
|
@ -0,0 +1,8 @@
|
||||||
|
Description:
|
||||||
|
Explain the generator
|
||||||
|
|
||||||
|
Example:
|
||||||
|
rails generate install Thing
|
||||||
|
|
||||||
|
This will create:
|
||||||
|
what/will/it/create
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Moderation < ActiveRecord::Base
|
||||||
|
include TheModerator::ModerationModel
|
||||||
|
end
|
Loading…
Reference in New Issue