diff options
| author | Kir | 2011-10-31 16:16:45 +0400 |
|---|---|---|
| committer | Kir | 2011-10-31 16:16:45 +0400 |
| commit | 7a540a454e4b2c2ccac5f6e542fe5130dbd05c8f (patch) | |
| tree | ddab265d7f62493f0e84a3b7cfbef06b2112123d /lib/generators | |
| parent | a99eda077cd84e42bb526ffecc4bc59c4c1929de (diff) | |
| download | inboxes-7a540a454e4b2c2ccac5f6e542fe5130dbd05c8f.tar.bz2 | |
Readme and initial changes
Diffstat (limited to 'lib/generators')
| -rw-r--r-- | lib/generators/inboxes/install_generator.rb | 40 | ||||
| -rw-r--r-- | lib/generators/inboxes/templates/install.rb | 36 |
2 files changed, 76 insertions, 0 deletions
diff --git a/lib/generators/inboxes/install_generator.rb b/lib/generators/inboxes/install_generator.rb new file mode 100644 index 0000000..d5d2a97 --- /dev/null +++ b/lib/generators/inboxes/install_generator.rb @@ -0,0 +1,40 @@ +require 'rails/generators' +require 'rails/generators/migration' + +module Inboxes + module Generators + class InstallGenerator < Rails::Generators::Base + include Rails::Generators::Migration + + source_root File.expand_path("../templates", __FILE__) + + # desc "Generates migration for Discussion, Message, Speaker and DiscussionView models" + + def self.orm + Rails::Generators.options[:rails][:orm] + end + + # def self.source_root + # File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) ) + # end + + def self.orm_has_migration? + [:active_record].include? orm + end + + def self.next_migration_number(dirname) + if ActiveRecord::Base.timestamped_migrations + migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + migration_number += 1 + migration_number.to_s + else + "%.3d" % (current_migration_number(dirname) + 1) + end + end + + def copy_migration + migration_template 'install.rb', 'db/migrate/install_inboxes.rb' + end + end + end +end diff --git a/lib/generators/inboxes/templates/install.rb b/lib/generators/inboxes/templates/install.rb new file mode 100644 index 0000000..ff83b40 --- /dev/null +++ b/lib/generators/inboxes/templates/install.rb @@ -0,0 +1,36 @@ +class InstallInboxes < ActiveRecord::Migration + def self.up + create_table :discussion_views do |t| + t.references :user + t.references :discussion + t.timestamps + end + + create_table :discussions do |t| + t.integer :messages_count, :default => 0 # counter cache + t.timestamps + end + + create_table :messages do |t| + t.references :user + t.references :discussion + t.text :body + + t.timestamps + end + + create_table :speakers do |t| + t.references :user + t.references :discussion + + t.timestamps + end + end + + def self.down + drop_table :speakers + drop_table :discussions + drop_table :discussion_views + drop_table :messages + end +end
\ No newline at end of file |
