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.

Introduced properties

Redefined properties

redef type SELF: AppGlobRoute

popcorn $ AppGlobRoute :: SELF

Type of this instance, automatically specialized in every class
redef fun match(uri: String): Bool

popcorn $ AppGlobRoute :: match

Does self match the req?
redef fun resolve_path(uri: String): String

popcorn $ AppGlobRoute :: resolve_path

Path without the trailing *.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun match(uri: String): Bool

popcorn :: AppRoute :: match

Does self match the req?
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parse_path_parameters(path: String)

popcorn :: AppParamRoute :: parse_path_parameters

Cut path into UriParts.
fun parse_uri_parameters(uri: String): Map[String, String]

popcorn :: AppParamRoute :: parse_uri_parameters

Extract parameter values from uri.
fun path: String

popcorn :: AppRoute :: path

Route relative path from server root.
protected fun path=(path: String)

popcorn :: AppRoute :: path=

Route relative path from server root.
fun resolve_path(uri: String): String

popcorn :: AppRoute :: resolve_path

Replace path parameters with concrete values from the uri.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun uri_root(uri: String): String

popcorn :: AppRoute :: uri_root

Remove resolved_path prefix from uri.
package_diagram popcorn::AppGlobRoute AppGlobRoute popcorn::AppParamRoute AppParamRoute popcorn::AppGlobRoute->popcorn::AppParamRoute popcorn::AppRoute AppRoute popcorn::AppParamRoute->popcorn::AppRoute ...popcorn::AppRoute ... ...popcorn::AppRoute->popcorn::AppRoute

Ancestors

class AppRoute

popcorn :: AppRoute

AppRoute provide services for path and uri manipulation and matching..
interface Object

core :: Object

The root of the class hierarchy.

Parents

class AppParamRoute

popcorn :: AppParamRoute

Parameterizable routes.

Class definitions

popcorn $ AppGlobRoute
# 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