Sinatra::AdvancedRoutes
Makes routes first class objects in Sinatra.
Check out sinatra-contrib you are looking for other fancy Sinatra extensions.
Installation
Add to your Gemfile
:
gem 'sinatra-advanced-routes'
If you are extending Sinatra::Base, register the extension manually :
require "sinatra/base"
require "sinatra/advanced_routes"
class Foo < Sinatra::Base
register Sinatra::AdvancedRoutes
end
Examples
Route manipulation
require "sinatra"
require "sinatra/advanced_routes"
admin_route = get "/admin" do
administrate_stuff
end
before do
if File.exists? "admin_password" then admin_route.activate
else admin_route.deactivate
end
end
first_route = get "/:name" do
end
other_route = get "/foo_:name" do
end
other_route.promote
Route inspection
require "some_sinatra_app"
SomeSinatraApp.each_route do |route|
puts "-" * 20
puts route.app.name
puts route.path
puts route.verb
puts route.file
puts route.line
puts route.pattern
puts route.keys
puts route.conditions
puts route.block
end
Some of that fields (like conditions or pattern) can be changed, which will take immediate effect on the routing.