Skip to content

Instantly share code, notes, and snippets.

@assaf
Created February 1, 2010 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assaf/291332 to your computer and use it in GitHub Desktop.
Save assaf/291332 to your computer and use it in GitHub Desktop.
# Allows something like:
# map.admin "/:action/:id", controller: :admin, conditions: { host: "admin.example.com" }
module ActionController
module Routing
class RouteSet
def extract_request_environment(request)
{ method: request.method, host: request.host }
end
end
class Route
def recognition_conditions
result = ["(match = #{Regexp.new(recognition_pattern).inspect}.match(path))"]
result << "[conditions[:method]].flatten.include?(env[:method])" if conditions[:method]
result << "conditions[:host] == env[:host]" if conditions[:host]
result
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment