Created
November 22, 2022 14:53
-
-
Save Drowze/c54fd0a85249f3b34c9e6f6256b827a8 to your computer and use it in GitHub Desktop.
bundle exec rails routes (with caching!)
This file contains 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/sh | |
# | |
# bundle exec rails routes (with caching!) by Drowze | |
# | |
# Just make an executable out of this and move into your path | |
routes_sha="" | |
if [[ -f config/routes.rb ]]; then | |
routes_blob=$(cat config/routes.rb) | |
if [[ -d config/routes ]]; then | |
all_routes_blob=$(cat config/routes/*) | |
routes_blob=$routes_blob$all_routes_blob | |
fi | |
routes_sha=$(echo "$routes_blob" | sha1sum | awk '{print $1}') | |
else | |
echo "Error: config/routes.rb doesn't exist. Maybe isn't a rails app?" | |
exit 1 | |
fi | |
repository=${PWD##*/} | |
mkdir -p /tmp/__rails_routes/$repository | |
if [[ -f /tmp/__rails_routes/$repository/$routes_sha ]]; then | |
cat /tmp/__rails_routes/$repository/$routes_sha | |
else | |
rm /tmp/__rails_routes/$repository/* | |
bundle exec rails routes | tee /tmp/__rails_routes/$repository/$routes_sha | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment