Class: Gruf::Hooks::Executor

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/gruf/hooks/executor.rb

Overview

Base class for a hook that allows execution at various points of gRPC server processes

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(hooks: nil) ⇒ Executor

Returns a new instance of Executor.



26
27
28
# File 'lib/gruf/hooks/executor.rb', line 26

def initialize(hooks: nil)
  @hooks = hooks || Gruf.hooks&.prepare || []
end

Instance Method Details

#call(name, arguments = {}) ⇒ Object

Execute a hook point for each registered hook in the registry

Parameters:

  • name (Symbol)
  • arguments (Hash) (defaults to: {})


36
37
38
39
40
41
42
43
44
# File 'lib/gruf/hooks/executor.rb', line 36

def call(name, arguments = {})
  name = name.to_sym

  @hooks.each do |hook|
    next unless hook.respond_to?(name)

    hook.send(name, **arguments)
  end
end