Module: Spikard::HandlerWrapper
- Included in:
- Spikard
- Defined in:
- lib/spikard/handler_wrapper.rb
Overview
Handler wrapper utilities for automatic file metadata conversion
Provides ergonomic handler patterns that automatically convert file metadata to UploadFile instances, eliminating boilerplate.
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 52 |
# 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| converted_body = Converters.convert_handler_body(body) handler.call(converted_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.
73 74 75 76 77 78 79 80 |
# File 'lib/spikard/handler_wrapper.rb', line 73 def wrap_handler(&handler) raise ArgumentError, 'block required for wrap_handler' unless handler lambda do |params, query, body| converted_body = Converters.convert_handler_body(body) handler.call(params, query, converted_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.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/spikard/handler_wrapper.rb', line 102 def wrap_handler_with_context(&handler) raise ArgumentError, 'block required for wrap_handler_with_context' unless handler lambda do |params, query, body| converted_body = Converters.convert_handler_body(body) context = { params: params, query: query, body: converted_body } handler.call(context) end end |