Skip to content

Instantly share code, notes, and snippets.

@drogus
Created April 24, 2012 19:39
Show Gist options
  • Save drogus/2483024 to your computer and use it in GitHub Desktop.
Save drogus/2483024 to your computer and use it in GitHub Desktop.
Router
require 'rack/request'
require 'journey'
require 'debugger'
separators = %w(/ . ?)
set = Journey::Routes.new
router = Journey::Router.new(set, {
:parameters_key => "rack.request.query_hash"
})
Router = lambda do |env|
router.call env
end
App = lambda do |env|
key = "rack.request.query_hash"
body = "#{key}: #{env[key]}"
[200, {}, body]
end
strexp = Journey::Router::Strexp.new(
"/foo/:id", # path
{ :id => /\d+/ }, # requirements
separators)
path = Journey::Path::Pattern.new(strexp)
set.add_route App,
path,
{:request_method=>/^GET$/},
{:foo => true}
$:.unshift(".")
require 'app'
run Router
gem "actionpack"
gem "thin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment