Class: MongoidForums::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_mongoid_forums_initializerObject



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_helperObject



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 options["current-user-helper"]
    current_user_helper = options["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_classObject



14
15
16
17
18
# File 'lib/generators/mongoid_forums/install_generator.rb', line 14

def determine_user_class
  @user_class = options["user-class"].presence ||
                ask("What is your user class called? [User]").presence ||
                'User'
end

#finishedObject



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_engineObject



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