Class: Galago::Router
- Inherits:
-
Object
- Object
- Galago::Router
- Defined in:
- lib/galago/router.rb,
lib/galago/router/dsl.rb,
lib/galago/router/path.rb,
lib/galago/router/route.rb,
lib/galago/router/errors.rb,
lib/galago/router/version.rb
Defined Under Namespace
Classes: ActionInvalid, DSL, Path, RequestMethodInvalid, Route
Constant Summary collapse
- REQUEST_METHODS =
[ "GET", "PATCH", "POST", "PUT", "DELETE" ]
- VERSION =
'0.2.0'
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #add_route(request_method, path, application) ⇒ Object
- #call(env) ⇒ Object
- #has_route?(request_method, path) ⇒ Boolean
-
#initialize(&block) ⇒ Router
constructor
A new instance of Router.
Constructor Details
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
18 19 20 |
# File 'lib/galago/router.rb', line 18 def routes @routes end |
Instance Method Details
#add_route(request_method, path, application) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/galago/router.rb', line 25 def add_route(request_method, path, application) if route = find_route_by_raw_path(path) route.add_endpoint(request_method, application) else route = Route.new(path) route.add_endpoint(request_method, application) @routes << route end end |
#call(env) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/galago/router.rb', line 40 def call(env) if route = find_route(env['PATH_INFO']) route.call(env) else Rack::Response.new("Not Found", 404).finish end end |
#has_route?(request_method, path) ⇒ Boolean
35 36 37 38 |
# File 'lib/galago/router.rb', line 35 def has_route?(request_method, path) route = find_route(path) route && route.allowed_methods.include?(request_method) end |