-
-
Save harssh/b46644d538aca14d1077af0c0382cbd5 to your computer and use it in GitHub Desktop.
rails_prep.rb - a ruby script to prepare a new rails application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# I use this bash script to create an rvm gemset for a new rails app | |
# and I call this script from my rails_prep.rb ruby script | |
# | |
echo "create new gemset for new rails application ..." | |
#rvm --create 1.9.2@$1 # <--> this instruction does not work, but the following does | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" && rvm --create @$1 | |
# ------------------------------- | |
# Use the gemset we just created | |
# -------------------------------------------------------------------------------------- | |
#rvm gemset use 1.9.2@$1_rails323 # <--> this does not work, but the following does | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" && rvm use @$1 | |
# the above line came from | |
# http://stackoverflow.com/questions/8716987/how-to-change-rvm-gemset-using-bash-script | |
# -------------------------------------------------------------------------------------- | |
echo "new gemset created" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# ========================================================================= | |
# This script will create a new rails app, a new git local repository, | |
# substitute a new Gemfile and .gitignore file from 'master' copies, | |
# run bundle install, run rspec:install and cucumber:install and | |
# create and modify files for the gem 'simplecov' | |
# | |
# ** YOU WILL NEED TO MODIFY THE FILE PATHS for your own use! ** | |
# | |
# usage: ruby rails_prep app_name OR | |
# ./rails_prep app_name | |
# for example, to create a new rails app named 'blog': | |
# ruby rails_prep.rb blog | |
# -- OR -- | |
# ./rails_prep blog | |
# | |
# This script does not perform error checking! It assumes that the | |
# rails gem has already been installed. It also assumes that the | |
# master files exist in the hard coded directories. It also assumes | |
# that you are using (and your Gemfile includes) rspec, cucumber & | |
# simplecov. | |
# ========================================================================= | |
# | |
require 'fileutils' | |
# ------------- | |
# -- Methods -- | |
# ------------- | |
def modify_files(fn) | |
# this method adds the 'require simplecov' | |
# instruction to the file whose name is | |
# passed as an argument | |
puts "accessing #{fn} ..." | |
f = File.open(fn, "r") | |
f = f.readlines | |
File.open(fn, "w") do |x| | |
s = "require 'simplecov'\n\n" | |
s = [s] | |
contents = s.concat(f) | |
x.puts contents | |
end | |
end | |
# ************************** | |
# *** Begin Main Routine *** | |
# ************************** | |
if ARGV[0].nil? | |
puts "**************************************" | |
puts "*** Forgetting something? ***" | |
puts "*** Please pass the rails app name ***" | |
puts "*** (nothing done) ***" | |
puts "**************************************" | |
exit | |
end | |
app_name = ARGV[0] | |
# ---------------------------------------------------------------- | |
# -- create gemset for use with new rails application -- | |
# (I use a bash script here because I could not figure out -- | |
# how to create and use rvm gemsets from within a ruby script) -- | |
# ---------------------------------------------------------------- | |
puts "creating gemset for use with new rails app ..." | |
`./create_gemset #{app_name}` | |
# ----------------------------- | |
# create new rails application | |
# ----------------------------- | |
puts "create new rails application #{app_name} (please be patient)..." | |
result = `rails new #{app_name} -T` | |
if result.match("Rails is not currently installed") | |
puts "Oops! rails gem is not installed. Exiting ..." | |
exit | |
#`gem install rails` | |
#`rails new #{app_name} -T` | |
end | |
# change to the newly created rails app directory | |
FileUtils.cd(app_name) | |
# -------------------------------- | |
# configure new rails application | |
# -------------------------------- | |
# | |
# setup for git | |
# | |
puts "copy master .gitignore file ..." | |
`cp ~/rails_projects/master_files/gitignore .gitignore` | |
puts "creating git repository ..." | |
`git init` | |
puts "configure git for color output ..." | |
`git config color.ui true` | |
# | |
# replace default Gemfile with my master & install gems | |
# | |
puts "copy master Gemfile ..." | |
`cp ~/rails_projects/master_files/Gemfile Gemfile` | |
puts "install gems (please be patient)..." | |
`bundle install` | |
# | |
# setup app for testing | |
# | |
puts "setup rspec folders ..." | |
`rails generate rspec:install` | |
puts "setup cucumber folders ..." | |
`rails generate cucumber:install` | |
puts "set up development and test databases ..." | |
`rake db:migrate` | |
`rake db:test:prepare` | |
puts "copy 'training wheels' files (web_steps.rb, etc.)" | |
`rails generate cucumber_rails_training_wheels:install` | |
puts "copy master .simplecov file ..." | |
`cp ~/rails_projects/master_files/simplecov .simplecov` | |
puts "modifying test framework files to use simplecov ..." | |
puts "modifying env.rb ..." | |
modify_files("/Users/rab/rails_projects/#{app_name}/features/support/env.rb") | |
puts "modifying spec_helper.rb" | |
modify_files("/Users/rab/rails_projects/#{app_name}/spec/spec_helper.rb") | |
puts "** Done! **" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment