-
Notifications
You must be signed in to change notification settings - Fork 341
Switching between projects where some use spring and some don't
Paul Dobbins edited this page Jan 25, 2014
·
3 revisions
First, setup spring per the installation instructions, making sure to perform the binstubs step:
bundle exec spring binstub --all
Now, the challenge becomes: how do I use one method to execute spring-driven commands in this project and non-spring-driven commands in other projects that don't use spring.
One solution (for bash shell):
# .bash_profile
rakec() { type ./bin/rake >/dev/null; if [ $? -eq 0 ]; then ./bin/rake $*; else bundle exec rake $*; fi }
railsc() { type ./bin/rails >/dev/null; if [ $? -eq 0 ]; then ./bin/rails $*; else rails $*; fi }
The naming I used here is just short for "rake command" and "rails command" -- use whatever you'd like. What the commands do is, they'll check if there's a binstub in the current project for the associated rake
/ rails
command, and, if so, use it. Otherwise it defaults to the standard bundle exec rake
/ rails
commands.
Now you can use the rakec
and railsc
commands directly, or integrate them into your own macros. For example:
# .bash_profile
rc() { railsc console $*; }
rs() { railsc server $*; }
rg() { railsc generate $*; }
rr() { rakec routes; }
rt() { rakec test $*; }
rtprep() { rakec db:test:prepare; }