Class: Kawaii::RouteHandler
- Inherits:
-
Object
- Object
- Kawaii::RouteHandler
- Includes:
- MethodChain, RenderMethods
- Defined in:
- lib/kawaii/route_handler.rb
Overview
Creates context for execution of route handler block provided by the user with #params and other objects.
Defined Under Namespace
Classes: ResponseError
Instance Attribute Summary (collapse)
-
- (Object) params
readonly
Params based on request visible in the route handler scope.
-
- (Object) request
readonly
Rack::Request object visible in the route handler scope.
Attributes included from MethodChain
Instance Method Summary (collapse)
-
- (Array) call(env)
Invokes the handler as a normal Rack application.
-
- (RouteHandler) initialize(scope, path_params, &block)
constructor
Creates a new RouteHandler wrapping a handler block.
Methods included from RenderMethods
Methods included from MethodChain
Constructor Details
- (RouteHandler) initialize(scope, path_params, &block)
Creates a new RouteHandler wrapping a handler block.
22 23 24 25 26 |
# File 'lib/kawaii/route_handler.rb', line 22 def initialize(scope, path_params, &block) self.parent_scope = scope @path_params = path_params @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Kawaii::MethodChain
Instance Attribute Details
- (Object) params (readonly)
Params based on request visible in the route handler scope.
14 15 16 |
# File 'lib/kawaii/route_handler.rb', line 14 def params @params end |
- (Object) request (readonly)
Rack::Request object visible in the route handler scope
16 17 18 |
# File 'lib/kawaii/route_handler.rb', line 16 def request @request end |
Instance Method Details
- (Array) call(env)
Invokes the handler as a normal Rack application.
31 32 33 34 35 |
# File 'lib/kawaii/route_handler.rb', line 31 def call(env) @request = Rack::Request.new(env) @params = @path_params.merge(@request.params.symbolize_keys) process_response(instance_exec(self, params, request, &@block)) end |