Class: SoarSc::Rack::Router
- Inherits:
-
Object
- Object
- SoarSc::Rack::Router
- Includes:
- BuilderSyntax
- Defined in:
- lib/soar_sc/rack/router.rb,
lib/soar_sc/rack/router/route.rb,
lib/soar_sc/rack/router/errors.rb,
lib/soar_sc/rack/router/version.rb,
lib/soar_sc/rack/router/http_method.rb,
lib/soar_sc/rack/router/builder_syntax.rb
Defined Under Namespace
Modules: BuilderSyntax, HttpMethod Classes: DuplicateRouteError, InvalidParameterError, Route
Constant Summary collapse
- EMPTY_STRING =
""- VERSION =
"1.0.0"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, routes = {}, &block) ⇒ Router
constructor
A new instance of Router.
Methods included from BuilderSyntax
#connect, #delete, #get, #head, #map, #options, #post, #put, #trace
Constructor Details
#initialize(app, routes = {}, &block) ⇒ Router
Returns a new instance of Router.
17 18 19 20 21 22 |
# File 'lib/soar_sc/rack/router.rb', line 17 def initialize(app, routes = {}, &block) @app = app @routes = [] routes.each { |(p, a)| add_route(Route.new(HttpMethod::ANY, p, a)) } instance_eval(&block) if block_given? end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/soar_sc/rack/router.rb', line 24 def call(env) if route = @routes.detect { |r| r.matches?(env) } update_path_parameters!(env, route.extract_path_parameters(env)) route.action.call(env) else @app.call(env) end end |