Class: Gruf::Instrumentation::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/instrumentation/registry.rb

Overview

Registry of all hooks added

Defined Under Namespace

Classes: HookDescendantError

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Return a strategy type registry via a hash accessor syntax



50
51
52
# File 'lib/gruf/instrumentation/registry.rb', line 50

def [](name)
  _registry[name.to_sym]
end

.add(name, hook = nil, &block) ⇒ Class

Add an authentication strategy, either through a class or a block

Parameters:

Returns:

  • (Class)

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/gruf/instrumentation/registry.rb', line 37

def add(name, hook = nil, &block)
  base = Gruf::Instrumentation::Base
  hook ||= Class.new(base)
  hook.class_eval(&block) if block_given?

  raise HookDescendantError, "Hooks must descend from #{base}" unless hook.ancestors.include?(base)

  _registry[name.to_sym] = hook
end

.any?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/gruf/instrumentation/registry.rb', line 73

def any?
  to_h.keys.count > 0
end

.clearHash

Returns:

  • (Hash)


80
81
82
# File 'lib/gruf/instrumentation/registry.rb', line 80

def clear
  @_registry = {}
end

.eachObject

Iterate over each hook in the registry



57
58
59
60
61
# File 'lib/gruf/instrumentation/registry.rb', line 57

def each
  _registry.each do |name, s|
    yield name, s
  end
end

.to_hHash<Class>

Returns:

  • (Hash<Class>)


66
67
68
# File 'lib/gruf/instrumentation/registry.rb', line 66

def to_h
  _registry
end