Class: Pgbus::EventBus::Registry
- Inherits:
-
Object
- Object
- Pgbus::EventBus::Registry
- Includes:
- Singleton
- Defined in:
- lib/pgbus/event_bus/registry.rb
Instance Attribute Summary collapse
-
#subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Instance Method Summary collapse
- #clear! ⇒ Object
- #handlers_for(routing_key) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #setup_all! ⇒ Object
- #subscribe(pattern, handler_class, queue_name: nil) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
12 13 14 15 |
# File 'lib/pgbus/event_bus/registry.rb', line 12 def initialize @subscribers = [] @mutex = Mutex.new end |
Instance Attribute Details
#subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
10 11 12 |
# File 'lib/pgbus/event_bus/registry.rb', line 10 def subscribers @subscribers end |
Instance Method Details
#clear! ⇒ Object
39 40 41 |
# File 'lib/pgbus/event_bus/registry.rb', line 39 def clear! @mutex.synchronize { @subscribers.clear } end |
#handlers_for(routing_key) ⇒ Object
35 36 37 |
# File 'lib/pgbus/event_bus/registry.rb', line 35 def handlers_for(routing_key) @subscribers.select { |s| matches?(s.pattern, routing_key) } end |
#setup_all! ⇒ Object
31 32 33 |
# File 'lib/pgbus/event_bus/registry.rb', line 31 def setup_all! @subscribers.each(&:setup!) end |
#subscribe(pattern, handler_class, queue_name: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pgbus/event_bus/registry.rb', line 17 def subscribe(pattern, handler_class, queue_name: nil) subscriber = Subscriber.new( pattern: pattern, handler_class: handler_class, queue_name: queue_name ) @mutex.synchronize do @subscribers << subscriber end subscriber end |