Class: Gruf::Instrumentation::Registry
- Inherits:
-
Object
- Object
- Gruf::Instrumentation::Registry
- Defined in:
- lib/gruf/instrumentation/registry.rb
Overview
Registry of all hooks added
Defined Under Namespace
Classes: HookDescendantError
Class Method Summary collapse
-
.[](name) ⇒ Object
Return a strategy type registry via a hash accessor syntax.
-
.add(name, hook = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block.
- .any? ⇒ Boolean
- .clear ⇒ Hash
-
.each ⇒ Object
Iterate over each hook in the registry.
- .to_h ⇒ Hash<Class>
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
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
73 74 75 |
# File 'lib/gruf/instrumentation/registry.rb', line 73 def any? to_h.keys.count > 0 end |
.clear ⇒ Hash
80 81 82 |
# File 'lib/gruf/instrumentation/registry.rb', line 80 def clear @_registry = {} end |
.each ⇒ Object
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_h ⇒ Hash<Class>
66 67 68 |
# File 'lib/gruf/instrumentation/registry.rb', line 66 def to_h _registry end |