Created
April 10, 2012 14:31
-
-
Save jamiehodge/2351768 to your computer and use it in GitHub Desktop.
sinatra/mount
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
module Sinatra | |
module Mount | |
def mount(app, route="/#{app.name.downcase}") | |
%w{get post put delete patch options}.each do |method| | |
self.send method.to_sym, "#{route}*" do | |
app.call( | |
env.merge!( | |
'SCRIPT_NAME' => route.split('/').last, | |
'PATH_INFO' => params.delete('splat').join('/') | |
) | |
) | |
end | |
end | |
end | |
end | |
register Mount | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Note: the splat pulls in whatever follows, trailing slash or no trailing slash