Class: Hyde::Handlers::Handler
- Defined in:
- lib/hyde/probe/handler.rb
Overview
Probe that executes a callback on request
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Attributes inherited from Probe
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(path, parent:, &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, parent:, &exec) ⇒ Handler
Returns a new instance of Handler.
12 13 14 15 16 17 |
# File 'lib/hyde/probe/handler.rb', line 12 def initialize(path, parent:, &exec) super(path, parent: parent) @callback = exec @context = Hyde::ProbeContext.new(self) @response = nil end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
20 21 22 |
# File 'lib/hyde/probe/handler.rb', line 20 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
19 20 21 |
# File 'lib/hyde/probe/handler.rb', line 19 def response @response 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)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hyde/probe/handler.rb', line 36 def process(request) @response = nil return reject(request) unless request.path.match?(/^\/?$/) @request = request response = catch(:break) do @context.instance_exec(*request.splat, **request.param, &@callback) end return false unless response if @response and [String, File, IO].include? response.class @response.body = response throw :finish, @response end throw :finish, response end |