Class: OpenapiFirst::Router
- Inherits:
-
Object
- Object
- OpenapiFirst::Router
- Defined in:
- lib/openapi_first/router.rb
Constant Summary collapse
- ORIGINAL_PATH =
'openapi_first.path_info'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize(app, options) ⇒ Router
Returns a new instance of Router.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/openapi_first/router.rb', line 8 def initialize( app, ) @app = app @parent_app = .fetch(:parent_app, nil) @raise = .fetch(:raise_error, false) @not_found = .fetch(:not_found, :halt) spec = .fetch(:spec) @filepath = spec.filepath @router = build_router(spec.operations) end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openapi_first/router.rb', line 21 def call(env) env[OPERATION] = nil response = call_router(env) if env[OPERATION].nil? return @parent_app.call(env) if @parent_app # This should only happen if used via OpenapiFirst.middleware raise_error(env) if @raise return @app.call(env) if @not_found == :continue end response end |