Class: MongoidForums::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MongoidForums::Generators::InstallGenerator
- Defined in:
- lib/generators/mongoid_forums/install_generator.rb
Instance Method Summary collapse
- #add_mongoid_forums_initializer ⇒ Object
- #determine_current_user_helper ⇒ Object
- #determine_user_class ⇒ Object
- #finished ⇒ Object
- #mount_engine ⇒ Object
Instance Method Details
#add_mongoid_forums_initializer ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/mongoid_forums/install_generator.rb', line 42 def add_mongoid_forums_initializer path = "#{Rails.root}/config/initializers/mongoid_forums.rb" if File.exists?(path) puts "Skipping config/initializers/mongoid_forums.rb creation, as file already exists!" else puts "Adding mongoid_forums initializer (config/initializers/mongoid_forums.rb)..." template "initializer.rb", path require path end end |
#determine_current_user_helper ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/mongoid_forums/install_generator.rb', line 21 def determine_current_user_helper if ["current-user-helper"] current_user_helper = ["current-user-helper"] else current_user_helper = ask("What is the current_user helper called in your app? [current_user]") end current_user_helper = :current_user if current_user_helper.blank? puts "Defining mongoid_forums_user method inside ApplicationController..." mongoid_forums_user_method = %Q{ def mongoid_forums_user #{current_user_helper} end helper_method :mongoid_forums_user } inject_into_file("#{Rails.root}/app/controllers/application_controller.rb", mongoid_forums_user_method, :after => "ActionController::Base\n") end |
#determine_user_class ⇒ Object
14 15 16 17 18 |
# File 'lib/generators/mongoid_forums/install_generator.rb', line 14 def determine_user_class @user_class = ["user-class"].presence || ask("What is your user class called? [User]").presence || 'User' end |
#finished ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/mongoid_forums/install_generator.rb', line 60 def finished output = "\n\n" + ("*" * 53) output += %Q{\nDone! MongoidForums has been successfully installed. Yaaaaay! Here's what happened:\n\n} output += step("A new file was created at config/initializers/mongoid_forums.rb This is where you put MongoidForums's configuration settings.\n") output += step("The engine was mounted in your config/routes.rb file using this line: mount MongoidForums::Engine, :at => \"/forums\" If you want to change where the forums are located, just change the \"/forums\" path at the end of this line to whatever you want.") output += %Q{\nAnd finally: #{step("We told you that MongoidForums has been successfully installed and walked you through the steps.")}} output += "Thanks for using MongoidForums!" puts output end |
#mount_engine ⇒ Object
53 54 55 56 57 58 |
# File 'lib/generators/mongoid_forums/install_generator.rb', line 53 def mount_engine puts "Mounting MongoidForums::Engine at \"/forums\" in config/routes.rb..." insert_into_file("#{Rails.root}/config/routes.rb", :after => /routes.draw.do\n/) do %Q{ mount MongoidForums::Engine, :at => "/forums"\n} end end |