Class: Otto::RouteHandlers::BaseHandler
- Inherits:
-
Object
- Object
- Otto::RouteHandlers::BaseHandler
- Defined in:
- lib/otto/route_handlers/base.rb
Overview
Base class for all route handlers Provides common functionality and interface
Direct Known Subclasses
ClassMethodHandler, InstanceMethodHandler, LambdaHandler, LogicClassHandler
Instance Attribute Summary collapse
-
#otto_instance ⇒ Object
readonly
Returns the value of attribute otto_instance.
-
#route_definition ⇒ Object
readonly
Returns the value of attribute route_definition.
Instance Method Summary collapse
-
#call(env, extra_params = {}) ⇒ Array
Execute the route handler.
-
#initialize(route_definition, otto_instance = nil) ⇒ BaseHandler
constructor
A new instance of BaseHandler.
Constructor Details
#initialize(route_definition, otto_instance = nil) ⇒ BaseHandler
Returns a new instance of BaseHandler.
15 16 17 18 |
# File 'lib/otto/route_handlers/base.rb', line 15 def initialize(route_definition, otto_instance = nil) @route_definition = route_definition @otto_instance = otto_instance end |
Instance Attribute Details
#otto_instance ⇒ Object (readonly)
Returns the value of attribute otto_instance.
13 14 15 |
# File 'lib/otto/route_handlers/base.rb', line 13 def otto_instance @otto_instance end |
#route_definition ⇒ Object (readonly)
Returns the value of attribute route_definition.
13 14 15 |
# File 'lib/otto/route_handlers/base.rb', line 13 def route_definition @route_definition end |
Instance Method Details
#call(env, extra_params = {}) ⇒ Array
Execute the route handler
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/otto/route_handlers/base.rb', line 24 def call(env, extra_params = {}) @start_time = Otto::Utils.now_in_μs req = otto_instance ? otto_instance.request_class.new(env) : Otto::Request.new(env) res = otto_instance ? otto_instance.response_class.new : Otto::Response.new begin setup_request_response(req, res, env, extra_params) result, context = invoke_target(req, res) handle_response(result, res, context) if route_definition.response_type != 'default' rescue StandardError => e handle_execution_error(e, env, req, res, @start_time) end finalize_response(res) end |