Skip to content

Instantly share code, notes, and snippets.

@ryotakato
Last active December 12, 2015 08:39
Show Gist options
  • Save ryotakato/4745892 to your computer and use it in GitHub Desktop.
Save ryotakato/4745892 to your computer and use it in GitHub Desktop.
make rails application for local rails version option [-m] is use MongoDB ( gem 'mongoid')
#!/bin/bash
# MongoDB
mongodb=false
# option
while getopts ":m" opt; do
case $opt in
m ) mongodb=true ;;
\? ) echo "Usage: \"$0 [-m] #application_name#\" "
exit 1
esac
done
shift $(($OPTIND - 1))
# check parameter count
if [ $# -eq 0 ]; then
echo "Usage: \"$0 [-m] #application_name#\" " 1>&2
exit 1
fi
# application name
app=$1
# make app dir
mkdir ${app} || { echo "error : can not mkdir" ; exit 1 ; }
cd ${app} || { echo "error : can not cd" ; exit 1 ; }
# create Gemfile
cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails"
EOS
# install local rails
bundle install --path vendor/bundle
# create new application
if [ $mongodb = true ] ; then
bundle exec rails new ${app} --skip-bundle --skip-active-record
else
bundle exec rails new ${app} --skip-bundle
fi
# delete
rm Gemfile
rm Gemfile.lock
# move to above dir
mv -f ${app}/* .
mv -f ${app}/.gitignore .
rm -rf ${app}
# MongoDB need other gem
if [ $mongodb = true ] ; then
cat << EOS >> Gemfile
gem 'mongoid'
gem 'bson_ext'
EOS
fi
# install gem
bundle install --path vendor/bundle
# add ignore
echo '/vendor/bundle' >> .gitignore
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment