Module: Spikard::LifecycleHooks
- Included in:
- App
- Defined in:
- lib/spikard/app.rb
Overview
Lifecycle hooks support for Spikard applications
Instance Method Summary collapse
-
#on_error(&hook) ⇒ Proc
Register an onError lifecycle hook.
-
#on_request(&hook) ⇒ Proc
Register an onRequest lifecycle hook.
-
#on_response(&hook) ⇒ Proc
Register an onResponse lifecycle hook.
-
#pre_handler(&hook) ⇒ Proc
Register a preHandler lifecycle hook.
-
#pre_validation(&hook) ⇒ Proc
Register a preValidation lifecycle hook.
Instance Method Details
#on_error(&hook) ⇒ Proc
Register an onError lifecycle hook
Runs when an error occurs. Can customize error responses.
100 101 102 103 |
# File 'lib/spikard/app.rb', line 100 def on_error(&hook) native_hooks.add_on_error(hook) hook end |
#on_request(&hook) ⇒ Proc
Register an onRequest lifecycle hook
Runs before routing. Can inspect/modify the request or short-circuit with a response.
22 23 24 25 |
# File 'lib/spikard/app.rb', line 22 def on_request(&hook) native_hooks.add_on_request(hook) hook end |
#on_response(&hook) ⇒ Proc
Register an onResponse lifecycle hook
Runs after the handler executes. Can modify the response.
83 84 85 86 |
# File 'lib/spikard/app.rb', line 83 def on_response(&hook) native_hooks.add_on_response(hook) hook end |
#pre_handler(&hook) ⇒ Proc
Register a preHandler lifecycle hook
Runs after validation but before the handler. Ideal for authentication/authorization.
66 67 68 69 |
# File 'lib/spikard/app.rb', line 66 def pre_handler(&hook) native_hooks.add_pre_handler(hook) hook end |
#pre_validation(&hook) ⇒ Proc
Register a preValidation lifecycle hook
Runs after routing but before validation. Useful for rate limiting.
44 45 46 47 |
# File 'lib/spikard/app.rb', line 44 def pre_validation(&hook) native_hooks.add_pre_validation(hook) hook end |