Class: ForumMonster::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/forum_monster/install_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#plural_camel_case_nameObject (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_nameObject (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_nameObject (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_nameObject (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.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

.source_rootObject



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_controllersObject



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_migrationsObject



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_modelsObject



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_routesObject



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_viewsObject



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