
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.58 KB | hits: 16 | expires: Never
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