Class: Karafka::Web::Ui::Controllers::Requests::ExecutionWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/ui/controllers/requests/execution_wrapper.rb

Overview

Note:

This class is used internally by the Web UI to wrap controllers and inject execution hooks around any method call (before/after filters).

ExecutionWrapper delegates all method calls to the provided controller instance. Before and after each invocation, it runs the controller’s registered hooks.

This allows for cleaner separation of concerns and reusable hook logic.

Examples:

controller = SomeController.new
wrapper = ExecutionWrapper.new(controller)
wrapper.call # will run before(:call), call, then after(:call)

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ExecutionWrapper

Returns a new instance of ExecutionWrapper.

Parameters:

  • controller (Object)

    a controller instance responding to method calls



22
23
24
# File 'lib/karafka/web/ui/controllers/requests/execution_wrapper.rb', line 22

def initialize(controller)
  @controller = controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Delegates any method call to the controller and wraps it with before/after hooks

Parameters:

  • method_name (Symbol)

    the name of the method being called

  • args (Array)

    arguments passed to the method

  • block (Proc)

    optional block passed to the method

Returns:

  • (Object)

    the result of the delegated controller method for Roda to operate on



32
33
34
35
36
37
# File 'lib/karafka/web/ui/controllers/requests/execution_wrapper.rb', line 32

def method_missing(method_name, *args, &block)
  @controller.run_before_hooks(method_name)
  result = @controller.public_send(method_name, *args, &block)
  @controller.run_after_hooks(method_name)
  result
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Properly supports respond_to? checks by delegating to the controller

Parameters:

  • method_name (Symbol)

    the method name to check

  • include_private (Boolean) (defaults to: false)

    whether to include private methods

Returns:

  • (Boolean)

    true if controller responds to the method



44
45
46
# File 'lib/karafka/web/ui/controllers/requests/execution_wrapper.rb', line 44

def respond_to_missing?(method_name, include_private = false)
  @controller.respond_to?(method_name, include_private)
end