Created
December 28, 2014 20:04
-
-
Save NullVoxPopuli/8c8af217b7404336c72a to your computer and use it in GitHub Desktop.
Route Recognizer to replace the broken Rails 3+'s recognize_path
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
class RouteRecognizer | |
include Singleton | |
ROUTE_LIST = Rails.application.routes.routes.collect{|r| r.path.spec.to_s} | |
REGEX_ROUT_LIST = ROUTE_LIST.map{|r| | |
Regexp.new(r.gsub(/\:(.*)id/, "(\d+)").gsub("(.:format)", "")) | |
} | |
def self.is_route?(path) | |
REGEX_ROUT_LIST.each do |regex| | |
return true if !!(path =~ regex) | |
end | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment