Skip to content

Instantly share code, notes, and snippets.

@cyx
Forked from vangberg/zuc.rb
Created August 17, 2011 20:05
Show Gist options
  • Save cyx/1152467 to your computer and use it in GitHub Desktop.
Save cyx/1152467 to your computer and use it in GitHub Desktop.
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