-
-
Save jacquescrocker/1029861 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 | |
module RouteWithAmbiguousPath | |
def route(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 | |
super(verb, path, options, &block) | |
end | |
end | |
def self.registered(app) | |
app.class_eval do | |
class << self | |
include RouteWithAmbiguousPath | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment