Class: Plumbing::Provider::Router
- Inherits:
-
Object
- Object
- Plumbing::Provider::Router
show all
- Defined in:
- lib/plumbing/provider/router.rb
Defined Under Namespace
Classes: DynamicRoute, InvalidPath, Query, Route, StaticRoute, WildcardRoute
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
90
91
92
93
94
|
# File 'lib/plumbing/provider/router.rb', line 90
def initialize
@static_routes = {}
@dynamic_routes = Set.new
@wildcard_routes = Set.new
end
|
Instance Method Details
#dynamic?(path) ⇒ Boolean
115
|
# File 'lib/plumbing/provider/router.rb', line 115
def dynamic?(path) = path.include?(":")
|
#query(path) ⇒ Object
107
108
109
110
111
112
113
|
# File 'lib/plumbing/provider/router.rb', line 107
def query path
path = _clean path
route = _static_route_for(path) || _dynamic_route_for(path) || _wildcard_route_for(path)
raise InvalidPath.new(path) if route.nil?
Query.new(route: route, path: path)
end
|
#register(path) ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/plumbing/provider/router.rb', line 96
def register path
path = _clean path
if wildcard?(path)
_register_wildcard(path)
elsif dynamic?(path)
_register_dynamic(path)
else
_register_static(path)
end
end
|
#wildcard?(path) ⇒ Boolean
117
|
# File 'lib/plumbing/provider/router.rb', line 117
def wildcard?(path) = path.split("/").last == "*"
|