Module: Karafka::Web::Ui::Controllers::Requests::Hookable
- Included in:
- BaseController
- Defined in:
- lib/karafka/web/ui/controllers/requests/hookable.rb
Overview
Adds before/after hook support for controller methods.
This module allows registering callbacks that run before and after any named method (e.g., call
, show
) or for all methods.
Hooks are inherited from parent controllers, making it easy to define shared behavior across a hierarchy.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Hook into class inclusion to extend DSL.
Instance Method Summary collapse
-
#run_after_hooks(action_name) ⇒ Object
Run all after hooks matching the action.
-
#run_before_hooks(action_name) ⇒ Object
Run all before hooks matching the action.
Class Method Details
.included(base) ⇒ Object
Hook into class inclusion to extend DSL
33 34 35 |
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 33 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#run_after_hooks(action_name) ⇒ Object
Run all after hooks matching the action
89 90 91 92 93 |
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 89 def run_after_hooks(action_name) self.class.after_hooks.each do |actions, block| instance_exec(&block) if actions.empty? || actions.include?(action_name) end end |
#run_before_hooks(action_name) ⇒ Object
Run all before hooks matching the action
80 81 82 83 84 |
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 80 def run_before_hooks(action_name) self.class.before_hooks.each do |actions, block| instance_exec(&block) if actions.empty? || actions.include?(action_name) end end |