Skip to content

Instantly share code, notes, and snippets.

@gotmayonase
Created January 9, 2020 21:56
Show Gist options
  • Save gotmayonase/9fd3191bbc15893212cc179a07de5e87 to your computer and use it in GitHub Desktop.
Save gotmayonase/9fd3191bbc15893212cc179a07de5e87 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
repo_path = File.expand_path('../../', __FILE__)
cache_file_path = File.join(repo_path, '/tmp/cached_routes')
cache_mtime = File.exists?(cache_file_path) && File.mtime(cache_file_path)
highest_routes_mtime = (Dir[File.join(repo_path,'/config/routes/**')] + [File.join(repo_path,'config/routes.rb')]).map { |f| File.mtime(f) }.max
if !cache_mtime || highest_routes_mtime > cache_mtime
`#{File.join(repo_path,'bin/rake')} routes > #{cache_file_path}`
puts `cat #{cache_file_path}`
else
puts `cat #{cache_file_path}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment