Class: Landline::Handlers::Handler
- Defined in:
- lib/landline/probe/handler.rb
Overview
Probe that executes a callback on request
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Probe
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(path, **args, &exec) ⇒ Handler
constructor
A new instance of Handler.
-
#process(request) ⇒ Boolean
Method callback on successful request navigation.
Methods inherited from Node
Constructor Details
#initialize(path, **args, &exec) ⇒ Handler
Returns a new instance of Handler.
12 13 14 15 |
# File 'lib/landline/probe/handler.rb', line 12 def initialize(path, **args, &exec) super(path, **args) @callback = exec end |
Instance Method Details
#process(request) ⇒ Boolean
Method callback on successful request navigation. Runs block supplied with object initialization. Request’s #splat and #param are passed to block.
Callback’s returned should be one of viable responses:
-
Response object
-
An array that matches Rack return form
-
An array that matches old (Rack 2.x) return form
-
A string (returned as HTML with code 200)
-
false (bounces the request to next handler)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/landline/probe/handler.rb', line 31 def process(request) origin, context = get_context(request) return reject(request) unless request.path.match?(/^\/?$/) response = catch(:break) do context.instance_exec(*request.splat, **request.param, &@callback) end return false unless response oresponse = origin.response if oresponse and [String, File, IO].include? response.class oresponse.body = response throw :finish, oresponse end throw :finish, response end |