Created
June 1, 2010 00:39
-
-
Save 13k/420425 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/ruby | |
| require 'optparse' | |
| def read_paths_from_file(file) | |
| File.new(file).readlines.map(&:strip) | |
| end | |
| def request_params(path, method = :get) | |
| ActionController::Routing::Routes.recognize_path(path, {:method => method}) | |
| end | |
| options = { | |
| :method => :get, | |
| :env => 'development' | |
| } | |
| OptionParser.new do |opts| | |
| #opts.on('-c', '--config', 'Environment config directory') do |c| | |
| #end | |
| opts.on('-e', '--env ENV', 'Rails env') do |e| | |
| options[:env] = e | |
| end | |
| opts.on('-i', '--input FILE', 'File to read URLs from (one per line)') do |i| | |
| options[:input] = i | |
| end | |
| opts.on('-m', '--method METHOD', 'HTTP request method') do |m| | |
| options[:method] = m.downcase.to_sym | |
| end | |
| end.parse! | |
| if options[:input] | |
| abort "Input file #{options[:input]} doesn't exists" if !File.exists?(options[:input]) | |
| @urls = read_paths_from_file(options[:input]) | |
| else | |
| @urls = ARGV.clone | |
| end | |
| abort "Nothing to do" if @urls.empty? | |
| ENV['RAILS_ENV'] ||= options[:env] | |
| require 'config/environment' | |
| w = { | |
| :path => 0, | |
| :method => 0, | |
| :params => 0 | |
| } | |
| routes = @urls.map do |path| | |
| method = options[:method].to_s | |
| params = request_params(path, options[:method]) | |
| w[:path] = path.length if path.length > w[:path] | |
| w[:method] = method.length if method.length > w[:method] | |
| #cols_width[:params] = params.inspect.length if params.inspect.length > w[:params] | |
| {:path => path, :method => method.upcase, :params => params.inspect} | |
| end | |
| routes.each do |r| | |
| puts "%s %s %s" % [:path, :method, :params].map {|c| r[c].ljust(w[c])} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment