popcorn :: AppGlobRoute :: defaultinit
# Route with glob.
#
# Route variable part is suffixed with a star `*`:
# ~~~
# var route = new AppGlobRoute("/*")
# assert route.match("/")
# assert route.match("/user")
# assert route.match("/user/10")
# ~~~
#
# Glob routes can be combined with parameters:
# ~~~
# route = new AppGlobRoute("/user/:id/*")
# assert not route.match("/user")
# assert route.match("/user/10")
# assert route.match("/user/10/profile")
# ~~~
#
# Note that the star can be used directly on the end of an URI part:
# ~~~
# route = new AppGlobRoute("/user*")
# assert route.match("/user")
# assert route.match("/username")
# assert route.match("/user/10/profile")
# assert not route.match("/foo")
# ~~~
#
# For now, stars cannot be used inside a route, use URI parameters instead.
class AppGlobRoute
super AppParamRoute
# Path without the trailing `*`.
# ~~~
# var route = new AppGlobRoute("/user/:id/*")
# assert route.resolve_path("/user/10/profile") == "/user/10"
#
# route = new AppGlobRoute("/user/:userId/items/:itemId*")
# assert route.resolve_path("/user/Morriar/items/i156/desc") == "/user/Morriar/items/i156"
# ~~~
redef fun resolve_path(uri) do
var path = super
if path.has_suffix("*") then
return path.substring(0, path.length - 1).simplify_path
end
return path.simplify_path
end
redef fun match(uri) do
var path = resolve_path(uri)
return uri.has_prefix(path.substring(0, path.length - 1))
end
end
lib/popcorn/pop_routes.nit:178,1--229,3