Module: HelperMethods
- Included in:
- BootupGenerator
- Defined in:
- lib/generators/bootup/methods.rb,
lib/generators/bootup/authentication.rb
Instance Method Summary collapse
- #create_mongoid ⇒ Object
- #create_postgres ⇒ Object
- #fetch_database ⇒ Object
- #first_commit ⇒ Object
- #setup_authentication ⇒ Object
- #setup_gems ⇒ Object
- #setup_testing ⇒ Object
- #setup_view_stuff ⇒ Object
Instance Method Details
#create_mongoid ⇒ Object
25 26 27 28 29 30 |
# File 'lib/generators/bootup/methods.rb', line 25 def create_mongoid unless @db == "sqlite" log :bootup_log, "Generating Mongoid config" generate "mongoid:config" end end |
#create_postgres ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/generators/bootup/methods.rb', line 15 def create_postgres @username = ask("\n\nPlease enter you postgres username", :blue) @password = ask("\n\nPlease enter you postgres password. Leave blank if not applicable", :blue) log :bootup_log, "Initializing database.yml" template 'database.yml.erb', 'config/database.yml' log :bootup_log, "Creating database" rake("db:create") end |
#fetch_database ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/generators/bootup/methods.rb', line 3 def fetch_database db = ask("\n\nWhat database would you like to start off with? P-Postgres / M-Mongoid / Default-SQLite", :blue) case db when "P","p" 'postgres' when "M","m" 'mongoid' else 'sqlite' end end |
#first_commit ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/bootup/methods.rb', line 73 def first_commit log :bootup_log, "Initializing git repo" inside Rails.root do run "git init" end copy_file ".gitignore", ".gitignore" inside Rails.root do run "git add ." run "git commit -m 'Initial Commit'" end end |
#setup_authentication ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/bootup/authentication.rb', line 2 def setup_authentication @model = ask("\n\n What would you like to call your user model? Default: User", :blue) @model = "user" if @model.blank? @model = @model.downcase.singularize @models = @model.pluralize log :bootup_log, "Installing Sorcery" generate "sorcery:install --model #{@model.classify}" log :bootup_log, "Copying models and migrations" case @db when 'mongoid' template "authentication/models/user_mongoid.rb.erb", "app/models/#{@model}.rb" inside Rails.root do run "rm db/migrate/*" end else template "authentication/models/user_others.rb.erb", "app/models/#{@model}.rb" rake("db:migrate") end log :bootup_log, "Copying controllers" template "authentication/controllers/users_controller.rb.erb", "app/controllers/#{@models}_controller.rb" template "authentication/controllers/user_sessions_controller.rb.erb", "app/controllers/#{@model}_sessions_controller.rb" copy_file "authentication/controllers/pages_controller.rb", "app/controllers/pages_controller.rb" copy_file "authentication/controllers/application_controller.rb", "app/controllers/application_controller.rb" log :bootup_log, "Copying views" directory "authentication/views", "app/views" unless @model.blank? inside Rails.root do run "mv app/views/user_sessions app/views/#{@model}_sessions" run "mv app/views/users app/views/#{@models}" end end log :bootup_log, "Copying initializers" template "authentication/sorcery.rb.erb", "config/initializers/sorcery.rb" log :bootup_log, "Copying initializers" template "authentication/routes.rb.erb", "config/routes.rb" inside Rails.root do run "git add ." run "git commit -am 'Authentication with sorcery.'" end say "\n\n An application with basic authentication has been created for you. Start thin server by typing 'rails s' in your command line. Point your browser to localhost:3000 to see the application.\n\n", :green end |
#setup_gems ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/generators/bootup/methods.rb', line 63 def setup_gems log :bootup_log, "Copying Gemfile" template "Gemfile.erb", "Gemfile" log :bootup_log, "Running Bundler" Bundler.with_clean_env do run "bundle install" end end |
#setup_testing ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/generators/bootup/methods.rb', line 46 def setup_testing log :bootup_log, "Removing Tests.." inside Rails.root do run "rm -rf test/" end log :bootup_log, "Setting up Rspec.." generate "rspec:install" log :bootup_log, "Setting up Guard with a custom guardfile.." copy_file "Guardfile", "Guardfile" log :bootup_log, "Setting up spork" copy_file "spec_helper.rb", "spec/spec_helper.rb" end |
#setup_view_stuff ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/bootup/methods.rb', line 32 def setup_view_stuff log :bootup_log, "Installing Twitter Bootstrap" generate "bootstrap:install" log :bootup_log, "Copy application.js & initialize datatables to #datatables - Remember to change sorting" copy_file "application.js", "app/assets/javascripts/application.js" log :bootup_log, "Copying stylesheets" copy_file "application.css", "app/assets/stylesheets/application.css" log :bootup_log, "Installing Simple Form" generate "simple_form:install --bootstrap" end |