Created
March 17, 2011 17:06
-
-
Save vangberg/874706 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
def path matcher | |
lambda {|req| | |
return unless match = req.env["PATH_INFO"].match(/^\/(#{matcher})(\/|$)/) | |
path = match.captures[0] | |
req.env["SCRIPT_NAME"] += "/#{path}" | |
req.env["PATH_INFO"] = "/#{match.post_match}" | |
} | |
end | |
app = lambda {|env| | |
req = Rack::Request.new(env) | |
res = Rack::Response.new | |
case req | |
when path("users") then | |
case req | |
when path("all") then | |
res.write "here they are" | |
else | |
res.write "users" | |
end | |
when path("about") then | |
res.write "about" | |
else | |
res.write "fail" | |
end | |
res.status = 200 | |
res.finish | |
} | |
run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment