Skip to content

Instantly share code, notes, and snippets.

@jtrim
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save jtrim/749f80fefd558185e6a1 to your computer and use it in GitHub Desktop.

Select an option

Save jtrim/749f80fefd558185e6a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
ROUTES_CACHE_FILE="tmp/routes_cache.txt"
if [ "$1" == "clear" ]; then
if [ "$2" != "--yes" ]; then
echo -n "Removing ${ROUTES_CACHE_FILE}: are you sure? [yn] "
read yes
if [ "$yes" != "y" ]; then
echo "Didn't get 'y'. Bailing..."
exit 99
fi
fi
rm $ROUTES_CACHE_FILE
exit 0
fi
__routes_get_current_md5() {
tail -n 1 $ROUTES_CACHE_FILE | tr -d '\n'
}
__routes_new_md5() {
cat `find . -name "routes.rb" | sort | tr '\n' ' '` | md5 | tr -d '\n'
}
if [ -e $ROUTES_CACHE_FILE ]; then
if [ "$(__routes_get_current_md5)" == "$(__routes_new_md5)" ]; then
cat $ROUTES_CACHE_FILE
else
rm $ROUTES_CACHE_FILE
routes
fi
else
ROUTES=`bundle exec rake routes 2>&1`
ROUTES_RESULT=$?
if [ "$ROUTES_RESULT" != "0" ]; then
echo "Couldn't regenerate routes: rake routes failed:"
echo "$ROUTES"
exit $ROUTES_RESULT
else
echo "$ROUTES" > $ROUTES_CACHE_FILE
echo "$(__routes_new_md5)" >> $ROUTES_CACHE_FILE
fi
cat $ROUTES_CACHE_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment