Class: Consumer::HandlerRegistry
- Inherits:
-
Object
- Object
- Consumer::HandlerRegistry
- Includes:
- Configure, Log::Dependency
- Defined in:
- lib/consumer/handler_registry.rb
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Instance Method Summary collapse
- #count ⇒ Object
- #each(&block) ⇒ Object
- #entries ⇒ Object
- #register(handler) ⇒ Object
- #registered?(handler) ⇒ Boolean
Methods included from Configure
Instance Method Details
#count ⇒ Object
12 13 14 |
# File 'lib/consumer/handler_registry.rb', line 12 def count entries.count end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/consumer/handler_registry.rb', line 16 def each(&block) entries.each(&block) end |
#entries ⇒ Object
8 9 10 |
# File 'lib/consumer/handler_registry.rb', line 8 def entries @entries ||= Set.new end |
#register(handler) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/consumer/handler_registry.rb', line 20 def register(handler) logger.trace { "Registering handler (Handler: #{handler.name})" } if registered? handler = "Handler is already registered (Handler: #{handler.name})" logger.error { } raise Error, end entries << handler logger.debug { "Handler registered (Handler: #{handler.name})" } handler end |
#registered?(handler) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'lib/consumer/handler_registry.rb', line 36 def registered?(handler) entries.any? do |entry| return true if handler == entry next if entry.is_a?(Proc) handler === entry end end |