Class: ForumMonster::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ForumMonster::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/forum_monster/install_generator.rb
Instance Attribute Summary collapse
-
#plural_camel_case_name ⇒ Object
readonly
Returns the value of attribute plural_camel_case_name.
-
#plural_lower_case_name ⇒ Object
readonly
Returns the value of attribute plural_lower_case_name.
-
#singular_camel_case_name ⇒ Object
readonly
Returns the value of attribute singular_camel_case_name.
-
#singular_lower_case_name ⇒ Object
readonly
Returns the value of attribute singular_lower_case_name.
Class Method Summary collapse
Instance Method Summary collapse
- #create_controllers ⇒ Object
- #create_migrations ⇒ Object
- #create_models ⇒ Object
- #create_routes ⇒ Object
- #create_views ⇒ Object
Instance Attribute Details
#plural_camel_case_name ⇒ Object (readonly)
Returns the value of attribute plural_camel_case_name.
11 12 13 |
# File 'lib/generators/forum_monster/install_generator.rb', line 11 def plural_camel_case_name @plural_camel_case_name end |
#plural_lower_case_name ⇒ Object (readonly)
Returns the value of attribute plural_lower_case_name.
11 12 13 |
# File 'lib/generators/forum_monster/install_generator.rb', line 11 def plural_lower_case_name @plural_lower_case_name end |
#singular_camel_case_name ⇒ Object (readonly)
Returns the value of attribute singular_camel_case_name.
11 12 13 |
# File 'lib/generators/forum_monster/install_generator.rb', line 11 def singular_camel_case_name @singular_camel_case_name end |
#singular_lower_case_name ⇒ Object (readonly)
Returns the value of attribute singular_lower_case_name.
11 12 13 |
# File 'lib/generators/forum_monster/install_generator.rb', line 11 def singular_lower_case_name @singular_lower_case_name end |
Class Method Details
.next_migration_number(path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/generators/forum_monster/install_generator.rb', line 17 def self.next_migration_number(dirname) if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
.source_root ⇒ Object
13 14 15 |
# File 'lib/generators/forum_monster/install_generator.rb', line 13 def self.source_root @source_root ||= File.join(File.dirname(__FILE__), 'templates') end |
Instance Method Details
#create_controllers ⇒ Object
25 26 27 28 29 30 |
# File 'lib/generators/forum_monster/install_generator.rb', line 25 def create_controllers template "controllers/categories_controller.rb", "app/controllers/categories_controller.rb" template "controllers/forums_controller.rb", "app/controllers/forums_controller.rb" template "controllers/topics_controller.rb", "app/controllers/topics_controller.rb" template "controllers/posts_controller.rb", "app/controllers/posts_controller.rb" end |
#create_migrations ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/generators/forum_monster/install_generator.rb', line 53 def create_migrations migration_template 'migrations/categories.rb', 'db/migrate/create_categories_table.rb' migration_template 'migrations/forums.rb', 'db/migrate/create_forums_table.rb' migration_template 'migrations/topics.rb', 'db/migrate/create_topics_table.rb' migration_template 'migrations/posts.rb', 'db/migrate/create_posts_table.rb' migration_template 'migrations/user.rb', 'db/migrate/update_users_table.rb' end |
#create_models ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/forum_monster/install_generator.rb', line 32 def create_models @singular_camel_case_name = user_model.singularize.camelize @plural_camel_case_name = user_model.pluralize.camelize @singular_lower_case_name = user_model.singularize.underscore @plural_lower_case_name = user_model.pluralize.underscore template "models/category.rb", "app/models/category.rb" template "models/forum.rb", "app/models/forum.rb" template "models/topic.rb", "app/models/topic.rb" template "models/post.rb", "app/models/post.rb" end |
#create_routes ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/forum_monster/install_generator.rb', line 61 def create_routes route "resources :categories, :except => [:index, :show] resources :forums, :except => :index do resources :topics, :shallow => true, :except => :index do resources :posts, :shallow => true, :except => [:index, :show] end root :to => 'categories#index', :via => :get end" end |
#create_views ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/generators/forum_monster/install_generator.rb', line 44 def create_views directory "views/categories", "app/views/categories" directory "views/forums", "app/views/forums" directory "views/topics", "app/views/topics" directory "views/posts", "app/views/posts" template "public/stylesheets/forum-monster.css", "public/stylesheets/forum-monster.css" template "public/images/ruby.png", "public/images/ruby.png" end |