Module: Karafka::Web::Ui::Controllers::Requests::Hookable::ClassMethods

Defined in:
lib/karafka/web/ui/controllers/requests/hookable.rb

Overview

DSL methods for defining and inheriting hooks

Instance Method Summary collapse

Instance Method Details

#after(*actions, &block) { ... } ⇒ Object

Register an after hook

Parameters:

  • actions (Array<Symbol>)

    optional action names to match (e.g., :call)

  • block (Proc)

Yields:

  • a block to execute after matched actions



72
73
74
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 72

def after(*actions, &block)
  after_hooks << [actions, block]
end

#after_hooksArray

Returns accumulated after hooks.

Returns:

  • (Array)

    accumulated after hooks



54
55
56
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 54

def after_hooks
  @after_hooks ||= []
end

#before(*actions, &block) { ... } ⇒ Object

Register a before hook

Parameters:

  • actions (Array<Symbol>)

    optional action names to match (e.g., :call)

  • block (Proc)

Yields:

  • a block to execute before matched actions



63
64
65
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 63

def before(*actions, &block)
  before_hooks << [actions, block]
end

#before_hooksArray

Returns accumulated before hooks.

Returns:

  • (Array)

    accumulated before hooks



49
50
51
# File 'lib/karafka/web/ui/controllers/requests/hookable.rb', line 49

def before_hooks
  @before_hooks ||= []
end

#inherited(subclass) ⇒ Object

Inherit parent hooks into subclass

Parameters:

  • subclass (Class)

    the subclass inheriting from base controller



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

def inherited(subclass)
  super
  subclass.before_hooks.concat(before_hooks)
  subclass.after_hooks.concat(after_hooks)
end