Class: Gruf::Hooks::Registry
- Inherits:
-
Object
- Object
- Gruf::Hooks::Registry
- Defined in:
- lib/gruf/hooks/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
- .count ⇒ Integer
-
.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
52 53 54 |
# File 'lib/gruf/hooks/registry.rb', line 52 def [](name) _registry[name.to_sym] end |
.add(name, hook = nil, &block) ⇒ Class
Add an authentication strategy, either through a class or a block
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gruf/hooks/registry.rb', line 36 def add(name, hook = nil, &block) base = Gruf::Hooks::Base hook ||= Class.new(base) hook.class_eval(&block) if block_given? # all hooks require either the before, after, or around method raise NoMethodError unless hook.method_defined?(:before) || hook.method_defined?(:after) || hook.method_defined?(:around) || hook.method_defined?(:outer_around) raise HookDescendantError, "Hooks must descend from #{base}" unless hook.ancestors.include?(base) _registry[name.to_sym] = hook end |
.any? ⇒ Boolean
75 76 77 |
# File 'lib/gruf/hooks/registry.rb', line 75 def any? count > 0 end |
.clear ⇒ Hash
89 90 91 |
# File 'lib/gruf/hooks/registry.rb', line 89 def clear @_registry = {} end |
.count ⇒ Integer
82 83 84 |
# File 'lib/gruf/hooks/registry.rb', line 82 def count to_h.keys.count end |
.each ⇒ Object
Iterate over each hook in the registry
59 60 61 62 63 |
# File 'lib/gruf/hooks/registry.rb', line 59 def each _registry.each do |name, s| yield name, s end end |
.to_h ⇒ Hash<Class>
68 69 70 |
# File 'lib/gruf/hooks/registry.rb', line 68 def to_h _registry end |