From af16ec0982944d6c005e9a744efafab6677aba21 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Fri, 7 Jun 2013 11:01:57 +0400 Subject: [PATCH] Migration generator --- burden_web/lib/burden_web.rb | 3 ++- .../20130607070108_create_burden_runs.rb | 0 burden_web/spec/dummy/db/schema.rb | 2 +- dummy | 1 + lib/burden.rb | 2 ++ .../active_record/burden_generator.rb | 22 ------------------- lib/rails/generators/burden/install/USAGE | 8 +++++++ .../burden/install/install_generator.rb | 20 +++++++++++++++++ .../install/templates/create_burden_runs.rb | 4 ++-- 9 files changed, 36 insertions(+), 26 deletions(-) rename lib/generators/active_record/create_burden_runs.rb => burden_web/spec/dummy/db/migrate/20130607070108_create_burden_runs.rb (100%) create mode 120000 dummy delete mode 100644 lib/generators/active_record/burden_generator.rb create mode 100644 lib/rails/generators/burden/install/USAGE create mode 100644 lib/rails/generators/burden/install/install_generator.rb rename burden_web/spec/dummy/db/migrate/20130606131532_create_burden_runs.rb => lib/rails/generators/burden/install/templates/create_burden_runs.rb (88%) diff --git a/burden_web/lib/burden_web.rb b/burden_web/lib/burden_web.rb index 0251636..1e7583f 100644 --- a/burden_web/lib/burden_web.rb +++ b/burden_web/lib/burden_web.rb @@ -1,4 +1,5 @@ -require "burden_web/engine" +require 'burden' +require 'burden_web/engine' module BurdenWeb end diff --git a/lib/generators/active_record/create_burden_runs.rb b/burden_web/spec/dummy/db/migrate/20130607070108_create_burden_runs.rb similarity index 100% rename from lib/generators/active_record/create_burden_runs.rb rename to burden_web/spec/dummy/db/migrate/20130607070108_create_burden_runs.rb diff --git a/burden_web/spec/dummy/db/schema.rb b/burden_web/spec/dummy/db/schema.rb index 199f5bb..7d0ac3b 100644 --- a/burden_web/spec/dummy/db/schema.rb +++ b/burden_web/spec/dummy/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130606131532) do +ActiveRecord::Schema.define(:version => 20130607070108) do create_table "burden_runs", :force => true do |t| t.string "name" diff --git a/dummy b/dummy new file mode 120000 index 0000000..8458a15 --- /dev/null +++ b/dummy @@ -0,0 +1 @@ +burden_web/spec/dummy \ No newline at end of file diff --git a/lib/burden.rb b/lib/burden.rb index eb4c103..7366df7 100644 --- a/lib/burden.rb +++ b/lib/burden.rb @@ -8,6 +8,8 @@ require 'burden/storage' require 'burden/version' require 'burden/wrapper' +# require 'generators/burden/install_generator' + module Burden include Config::Helper diff --git a/lib/generators/active_record/burden_generator.rb b/lib/generators/active_record/burden_generator.rb deleted file mode 100644 index 3f1973e..0000000 --- a/lib/generators/active_record/burden_generator.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails/generators' -require 'rails/generators/migration' - -class BurdenGenerator < Rails::Generators::Base - include Rails::Generators::Migration - - def self.source_root - @source_root ||= File.dirname(__FILE__) - end - - def self.next_migration_number(dirname) - if ActiveRecord::Base.timestamped_migrations - Time.new.utc.strftime('%Y%m%d%H%M%S') - else - '%.3d' % (current_migration_number(dirname) + 1) - end - end - - def create_migration_file - migration_template 'create_burden_runs.rb', 'db/migrate/create_burden_runs.rb' - end -end diff --git a/lib/rails/generators/burden/install/USAGE b/lib/rails/generators/burden/install/USAGE new file mode 100644 index 0000000..c9fb09f --- /dev/null +++ b/lib/rails/generators/burden/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/rails/generators/burden/install/install_generator.rb b/lib/rails/generators/burden/install/install_generator.rb new file mode 100644 index 0000000..ece54ce --- /dev/null +++ b/lib/rails/generators/burden/install/install_generator.rb @@ -0,0 +1,20 @@ +require 'rails/generators' +require 'rails/generators/migration' + +module Burden + module Generators + class InstallGenerator < Rails::Generators::Base + include Rails::Generators::Migration + + source_root File.expand_path('../templates', __FILE__) + + def self.next_migration_number(path) + Time.now.utc.strftime("%Y%m%d%H%M%S") + end + + def create_migration + migration_template 'create_burden_runs.rb', 'db/migrate/create_burden_runs.rb' + end + end + end +end diff --git a/burden_web/spec/dummy/db/migrate/20130606131532_create_burden_runs.rb b/lib/rails/generators/burden/install/templates/create_burden_runs.rb similarity index 88% rename from burden_web/spec/dummy/db/migrate/20130606131532_create_burden_runs.rb rename to lib/rails/generators/burden/install/templates/create_burden_runs.rb index e68a384..9ed964d 100644 --- a/burden_web/spec/dummy/db/migrate/20130606131532_create_burden_runs.rb +++ b/lib/rails/generators/burden/install/templates/create_burden_runs.rb @@ -1,5 +1,5 @@ class CreateBurdenRuns < ActiveRecord::Migration - def up + def self.up create_table :burden_runs do |t| t.string :name t.boolean :success @@ -8,7 +8,7 @@ class CreateBurdenRuns < ActiveRecord::Migration end end - def down + def self.down drop_table :burden_runs end end