From fc72e412bc45840097a168ab0eac80171a275b28 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Tue, 26 Nov 2013 14:18:40 +0100 Subject: [PATCH] Add install generator for migration and default model --- lib/generators/the_moderator/install/USAGE | 8 ++++++++ .../the_moderator/install/install_generator.rb | 18 ++++++++++++++++++ .../install/templates/migration.rb | 14 ++++++++++++++ .../install/templates/moderation.rb | 3 +++ 4 files changed, 43 insertions(+) create mode 100644 lib/generators/the_moderator/install/USAGE create mode 100644 lib/generators/the_moderator/install/install_generator.rb create mode 100644 lib/generators/the_moderator/install/templates/migration.rb create mode 100644 lib/generators/the_moderator/install/templates/moderation.rb diff --git a/lib/generators/the_moderator/install/USAGE b/lib/generators/the_moderator/install/USAGE new file mode 100644 index 0000000..c9fb09f --- /dev/null +++ b/lib/generators/the_moderator/install/USAGE @@ -0,0 +1,8 @@ +Description: + Explain the generator + +Example: + rails generate install Thing + + This will create: + what/will/it/create diff --git a/lib/generators/the_moderator/install/install_generator.rb b/lib/generators/the_moderator/install/install_generator.rb new file mode 100644 index 0000000..f1cea3f --- /dev/null +++ b/lib/generators/the_moderator/install/install_generator.rb @@ -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 diff --git a/lib/generators/the_moderator/install/templates/migration.rb b/lib/generators/the_moderator/install/templates/migration.rb new file mode 100644 index 0000000..c86c041 --- /dev/null +++ b/lib/generators/the_moderator/install/templates/migration.rb @@ -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 diff --git a/lib/generators/the_moderator/install/templates/moderation.rb b/lib/generators/the_moderator/install/templates/moderation.rb new file mode 100644 index 0000000..0edec6e --- /dev/null +++ b/lib/generators/the_moderator/install/templates/moderation.rb @@ -0,0 +1,3 @@ +class Moderation < ActiveRecord::Base + include TheModerator::ModerationModel +end