Created
June 16, 2011 17:59
-
-
Save ajsharp/1029827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sinatra | |
module AmbiguousRoutes | |
def self.registered(app) | |
app.class_eval do | |
class << self | |
private | |
def route_with_ambiguity(verb, path, options = {}, &block) | |
# don't modify routes that already defined with a format extension | |
case path | |
when Regexp | |
else | |
if path =~ /\..*$/ | |
pth, _, ext = path.split(/(\.)(.*)$/) | |
path = /^#{pth}(\.#{ext}|)$/ | |
else | |
path = /^#{path}(\.json|)$/ | |
end | |
end | |
route_without_ambiguity(verb, path, options, &block) | |
end | |
# alias_method :route_without_ambiguity, :route | |
# alias_method :route, :route_with_ambiguity | |
alias_method_chain :route, :ambiguity | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment