Last active
February 20, 2025 15:05
-
-
Save mimosa/d78e2541ebb24a20095e753cf9764161 to your computer and use it in GitHub Desktop.
add instrument to typhoeus
This file contains hidden or 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
ROUTE_PATTERN = { | |
/^\d+$/ => '<id>', | |
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ => '<uuid>' | |
}.freeze | |
def to_http_route(path, patterns = ROUTE_PATTERN) | |
path.downcase.split('/').map do |segment| | |
next segment if segment.empty? | |
patterns.find { |pattern, _| segment =~ pattern }&.last || segment | |
end.join('/') | |
end |
Comments are disabled for this gist.