
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
A simple and generic named routes api. It works really well with Sinatra.
gem install named-routes
require "named-routes"
You can define a named route by providing the name of the method and the definition.
NamedRoutes.path(:user, "/users/:user_id") # => "/users/:user_id"
You can use this in conjunction with Sinatra routes like so:
include NamedRoutes
get path(:user, "/users/:user_id") do
# ...
end
If you have multiple handlers for the same route, you can use the block syntax:
include NamedRoutes
path(:user, "/users/:user_id") do |_|
get _ do
# ...
end
post _ do
# ...
end
end
You can also define prefixes on the route definitions:
include NamedRoutes
paths.prefix = "admin"
path(:user, "/users/:user_id") do |_| # => /admin/users/:user_id
get _ do
# ...
end
post _ do
# ...
end
end
You can access the routes by doing the following.
include NamedRoutes
paths.host = "example.com"
path(:user, "/users/:user_id")
paths.user(:user_id => 42) # => "/users/42"
paths.http.user(:user_id => 42) # => "http://example.com/users/42"
paths.https.user(:user_id => 42) # => "https://example.com/users/42"
It also works with prefixes:
include NamedRoutes
paths.host = "example.com"
paths.prefix = "admin"
path(:user, "/users/:user_id")
paths.user(:user_id => 42) # => "/users/42"
paths.http.user(:user_id => 42) # => "http://example.com/admin/users/42"
paths.https.user(:user_id => 42) # => "https://example.com/admin/users/42"
And with query params:
include NamedRoutes
paths.host = "example.com"
paths.prefix = "admin"
path(:user, "/users/:user_id")
paths.user(:user_id => 42, :foo => "bar of soap") # => "/users/42&foo=bar+of+soap"
You can also inherit Routes to have different sets of Routes. This is useful if you want route sets with different prefixes.
class AdminRoutes < NamedRoutes::Routes
self.prefix = "admin"
end
class PartayRoutes < NamedRoutes::Routes
self.prefix = "partay"
end
def admin_paths
AdminRoutes
end
def partay_paths
PartayRoutes
end
get admin_paths.path(:user, "/users/:user_id") do # => /admin/users/:user_id
# ...
end
admin_paths.user(:user_id => 42) # => "/admin/users/42"
get partay_paths.path(:user, "/users/:user_id") do # => /partay/users/:user_id
# ...
end
partay_paths.user(:user_id => 42, :beer => "pabst") # => "/partay/users/42&beer=pabst"
Copyright (c) 2010 Brian Takita. This software is licensed under the MIT License.
FAQs
Unknown package
We found that named-routes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.