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: StrategyDescendantError
Class Method Summary collapse
-
.[](name) ⇒ Gruf::Instrumentation::Base|NilClass
Return a strategy type registry via a hash accessor syntax.
-
.add(name, strategy = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block.
-
.any? ⇒ Boolean
Return true if there are any registered instrumentation strategies.
-
.clear ⇒ Hash
Clear all existing strategies from the registry.
-
.each ⇒ Object
Iterate over each hook in the registry.
-
.to_h ⇒ Hash<Class>
Return the registry represented as a Hash object.
Class Method Details
.[](name) ⇒ Gruf::Instrumentation::Base|NilClass
Return a strategy type registry via a hash accessor syntax
59 60 61 |
# File 'lib/gruf/instrumentation/registry.rb', line 59 def [](name) _registry[name.to_sym] end |
.add(name, strategy = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block
Gruf::Instrumentation::Registry.add(:my_instrumentor, MyInstrumentor)
a block that can be built as a strategy instead
44 45 46 47 48 49 50 51 52 |
# File 'lib/gruf/instrumentation/registry.rb', line 44 def add(name, strategy = nil, &block) base = Gruf::Instrumentation::Base strategy ||= Class.new(base) strategy.class_eval(&block) if block_given? raise StrategyDescendantError, "Hooks must descend from #{base}" unless strategy.ancestors.include?(base) _registry[name.to_sym] = strategy end |
.any? ⇒ Boolean
Return true if there are any registered instrumentation strategies
82 83 84 |
# File 'lib/gruf/instrumentation/registry.rb', line 82 def any? to_h.keys.count > 0 end |
.clear ⇒ Hash
Returns Clear all existing strategies from the registry.
89 90 91 |
# File 'lib/gruf/instrumentation/registry.rb', line 89 def clear @_registry = {} end |
.each ⇒ Object
Iterate over each hook in the registry
66 67 68 69 70 |
# File 'lib/gruf/instrumentation/registry.rb', line 66 def each _registry.each do |name, s| yield name, s end end |
.to_h ⇒ Hash<Class>
Return the registry represented as a Hash object
75 76 77 |
# File 'lib/gruf/instrumentation/registry.rb', line 75 def to_h _registry end |