def route(verb, path, options={}, &block) rake routes

path => "/hi/:ba"
block, pattern, keys, conditions = compile! verb, path, block, options
pattern => /^\/hi\/([^\/?#]+)$/
22: self = Sinatra::Application
(rdb:1) disp self.routes
23: self.routes = {"GET"=>[[/^\/$/, [], [], #<Proc:0x90f5484@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/hi\/([^\/?#]+)$/, ["ba"], [], #<Proc:0x9164bf4@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/hi$/, [], [], #<Proc:0x8ff33c4@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/bye$/, [], [], #<Proc:0x8d42af8@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>]], "HEAD"=>[[/^\/$/, [], [], #<Proc:0x8e1e774@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/hi\/([^\/?#]+)$/, ["ba"], [], #<Proc:0x914f880@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/hi$/, [], [], #<Proc:0x8f77b70@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>], [/^\/bye$/, [], [], #<Proc:0x94763b0@/home/wenbo/.rvm/gems/ruby-1.9.2-p180/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152>]]}

(rdb:1) disp $0
4: $0 = hi.rb
(rdb:1) disp app_file
5: app_file = hi.rb


  704      def route!(base = settings, pass_block=nil)
   705        debugger
=> 706        if routes = base.routes[@request.request_method]
   707          routes.each do |pattern, keys, conditions, block|
   708            pass_block = process_route(pattern, keys, conditions) do
   709              route_eval(&block)
   710            end
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
  Rails.application.reload_routes!
  all_routes = Rails.application.routes.routes

  if ENV['CONTROLLER']
    all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
  end

  routes = all_routes.collect do |route|

    reqs = route.requirements.dup
    reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
    reqs = reqs.empty? ? "" : reqs.inspect

    {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
  end

  routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route

  name_width = routes.map{ |r| r[:name].length }.max
  verb_width = routes.map{ |r| r[:verb].length }.max
  path_width = routes.map{ |r| r[:path].length }.max

  routes.each do |r|
    puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
  end
end

你可能感兴趣的:(option)