Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created August 15, 2008 06:01
Show Gist options
  • Select an option

  • Save carllerche/5542 to your computer and use it in GitHub Desktop.

Select an option

Save carllerche/5542 to your computer and use it in GitHub Desktop.
# Router.prepare do |r|
# r.match(:domain => "foo", :user_agent => "something").to
# r.match("/blah/blah").to
# end
def match(request)
cached_path = request.path
cached_domain = request.domain
cached_user_agent = request.user_agent
if (cached_domain == "foo") && (cached_user_agent == "something")
[0, {:action => "index"}]
elsif (/^\/blah\/blah$/ =~ cached_path )
[1, {:action => "index"}]
else
[nil, {}]
end
end
def match(request)
cached_path = request.path
cached_method = request.method
if (/^\/users(?:\/index)?(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get")
[0, {:controller => "users", :format => (path1), :action => "index"}]
elsif (/^\/users(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "post")
[1, {:controller => "users", :format => (path1), :action => "create"}]
elsif (/^\/users\/new(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get")
[2, {:controller => "users", :format => (path1), :action => "new"}]
elsif (/^\/users\/one(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "get")
[3, {:controller => "users", :format => (path1), :action => "one"}]
elsif (/^\/users\/four(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "delete")
[4, {:controller => "users", :format => (path1), :action => "four"}]
elsif (/^\/users\/two(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "post")
[5, {:controller => "users", :format => (path1), :action => "two"}]
elsif (/^\/users\/three(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1 = $1) || true)) && (cached_method == "put")
[6, {:controller => "users", :format => (path1), :action => "three"}]
elsif (/^\/users\/([^\/.,;?]+)(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "get")
[7, {:controller => "users", :format => (path2), :action => "show", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/eight(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "delete")
[8, {:controller => "users", :format => (path2), :action => "eight", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/five(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "get")
[9, {:controller => "users", :format => (path2), :action => "five", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/edit(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "get")
[10, {:controller => "users", :format => (path2), :action => "edit", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/six(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "post")
[11, {:controller => "users", :format => (path2), :action => "six", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/delete(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "get")
[12, {:controller => "users", :format => (path2), :action => "delete", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)\/seven(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "put")
[13, {:controller => "users", :format => (path2), :action => "seven", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "put")
[14, {:controller => "users", :format => (path2), :action => "update", :id => (path1)}]
elsif (/^\/users\/([^\/.,;?]+)(?:\.([^\/.,;?]+))?$/ =~ cached_path && ((path1, path2 = $1, $2) || true)) && (cached_method == "delete")
[15, {:controller => "users", :format => (path2), :action => "destroy", :id => (path1)}]
else
[nil, {}]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment