Module: Spikard::HandlerWrapper
- Included in:
- Spikard
- Defined in:
- lib/spikard/handler_wrapper.rb
Overview
Handler wrapper utilities.
UploadFile conversion now happens in the Rust binding, so these wrappers simply forward the already-converted body/params.
Class Method Summary collapse
-
.wrap_body_handler {|body| ... } ⇒ Proc
Wrap a handler that receives only the request body.
-
.wrap_handler {|params, query, body| ... } ⇒ Proc
Wrap a handler that receives path params, query params, and body.
-
.wrap_handler_with_context {|context| ... } ⇒ Proc
Wrap a handler that receives a context hash with all request data.
Class Method Details
.wrap_body_handler {|body| ... } ⇒ Proc
Wrap a handler that receives only the request body
Automatically converts file metadata in the body to UploadFile instances.
43 44 45 46 47 48 49 50 51 |
# File 'lib/spikard/handler_wrapper.rb', line 43 def wrap_body_handler(&handler) raise ArgumentError, 'block required for wrap_body_handler' unless handler # Return a proc that matches the signature expected by Spikard::App # The actual handler receives path params, query params, and body from Rust lambda do |_params, _query, body| handler.call(body) end end |
.wrap_handler {|params, query, body| ... } ⇒ Proc
Wrap a handler that receives path params, query params, and body
Automatically converts file metadata in the body to UploadFile instances.
72 73 74 75 76 77 78 |
# File 'lib/spikard/handler_wrapper.rb', line 72 def wrap_handler(&handler) raise ArgumentError, 'block required for wrap_handler' unless handler lambda do |params, query, body| handler.call(params, query, body) end end |
.wrap_handler_with_context {|context| ... } ⇒ Proc
Wrap a handler that receives a context hash with all request data
Automatically converts file metadata in the body to UploadFile instances. Useful when you want all request data in a single hash.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/spikard/handler_wrapper.rb', line 100 def wrap_handler_with_context(&handler) raise ArgumentError, 'block required for wrap_handler_with_context' unless handler lambda do |params, query, body| context = { params: params, query: query, body: body } handler.call(context) end end |