Skip to content

Instantly share code, notes, and snippets.

@abachman
Created May 26, 2016 20:11
Show Gist options
  • Save abachman/c9c28da27d72ee3e0578041c3c8dcc94 to your computer and use it in GitHub Desktop.
Save abachman/c9c28da27d72ee3e0578041c3c8dcc94 to your computer and use it in GitHub Desktop.
groutes - a Rails routes grep helper
#!/bin/bash
#
# Add to your local ~/bin/ and search. Caches the `rake routes` command
# so it doesn't have to run again if config/routes hasn't changed.
#
if [ ! -f Rakefile -o ! -f config/routes.rb ]; then
echo "groutes will only work in rails project directories :("
exit 1
fi
if [ ! -f .rails_routes~ ]; then
echo "generate routes because cache doesn't exist"
bundle exec rake routes > .rails_routes~
fi
if [ ! -f .rails_routes_rb~ ]; then
echo "regenerate routes because config/routes.rb is newer than cache"
cp config/routes.rb .rails_routes_rb~
bundle exec rake routes > .rails_routes~
else
diff -q config/routes.rb .rails_routes_rb~
diff_status=$?
if [ "$diff_status" -ne 0 ]; then
echo "regenerate routes because config/routes.rb doesn't match previous version"
cp config/routes.rb .rails_routes_rb~
bundle exec rake routes > .rails_routes~
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment