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 | |
| parent | a99eda077cd84e42bb526ffecc4bc59c4c1929de (diff) | |
| download | inboxes-7a540a454e4b2c2ccac5f6e542fe5130dbd05c8f.tar.bz2 | |
Readme and initial changes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/generators/inboxes/install_generator.rb | 40 | ||||
| -rw-r--r-- | lib/generators/inboxes/templates/install.rb | 36 | ||||
| -rw-r--r-- | lib/inboxes.rb | 8 | ||||
| -rw-r--r-- | lib/inboxes/engine.rb | 4 | ||||
| -rw-r--r-- | lib/inboxes/railtie.rb | 16 |
5 files changed, 101 insertions, 3 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 diff --git a/lib/inboxes.rb b/lib/inboxes.rb index 2720101..29bb078 100644 --- a/lib/inboxes.rb +++ b/lib/inboxes.rb @@ -1,5 +1,7 @@ require "inboxes/version" +require "inboxes/railtie" +require "inboxes/engine" -module Inboxes - # Your code goes here... -end +# module Inboxes +# # Your code goes here... +# end diff --git a/lib/inboxes/engine.rb b/lib/inboxes/engine.rb new file mode 100644 index 0000000..061694e --- /dev/null +++ b/lib/inboxes/engine.rb @@ -0,0 +1,4 @@ +module Inboxes + class Engine < ::Rails::Engine + end +end
\ No newline at end of file diff --git a/lib/inboxes/railtie.rb b/lib/inboxes/railtie.rb new file mode 100644 index 0000000..5be6db5 --- /dev/null +++ b/lib/inboxes/railtie.rb @@ -0,0 +1,16 @@ +require 'rails' + +module Inboxes + class Railtie < ::Rails::Railtie #:nodoc: + initializer 'inboxes' do |app| + ActiveSupport.on_load(:active_record) do + # require 'kaminari/models/active_record_extension' + # ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension + end + + ActiveSupport.on_load(:action_view) do + # ::ActionView::Base.send :include, Kaminari::ActionViewExtension + end + end + end +end
\ No newline at end of file |
