Skip to content

Instantly share code, notes, and snippets.

@mimosa
Last active February 20, 2025 15:05
Show Gist options
  • Save mimosa/d78e2541ebb24a20095e753cf9764161 to your computer and use it in GitHub Desktop.
Save mimosa/d78e2541ebb24a20095e753cf9764161 to your computer and use it in GitHub Desktop.
add instrument to typhoeus
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.