Class: Easyop::Events::Bus::Custom
- Defined in:
- lib/easyop/events/bus/custom.rb
Overview
Wraps any user-supplied bus adapter.
The adapter must respond to:
#publish(event)
#subscribe(pattern, &block)
Optionally:
#unsubscribe(handle)
Instance Method Summary collapse
-
#initialize(adapter) ⇒ Custom
constructor
A new instance of Custom.
- #publish(event) ⇒ Object
- #subscribe(pattern, &block) ⇒ Object
- #unsubscribe(handle) ⇒ Object
Constructor Details
#initialize(adapter) ⇒ Custom
Returns a new instance of Custom.
28 29 30 31 32 33 34 35 |
# File 'lib/easyop/events/bus/custom.rb', line 28 def initialize(adapter) unless adapter.respond_to?(:publish) && adapter.respond_to?(:subscribe) raise ArgumentError, "Custom bus adapter must respond to #publish(event) and " \ "#subscribe(pattern, &block). Got: #{adapter.inspect}" end @adapter = adapter end |
Instance Method Details
#publish(event) ⇒ Object
37 38 39 |
# File 'lib/easyop/events/bus/custom.rb', line 37 def publish(event) @adapter.publish(event) end |
#subscribe(pattern, &block) ⇒ Object
41 42 43 |
# File 'lib/easyop/events/bus/custom.rb', line 41 def subscribe(pattern, &block) @adapter.subscribe(pattern, &block) end |
#unsubscribe(handle) ⇒ Object
45 46 47 |
# File 'lib/easyop/events/bus/custom.rb', line 45 def unsubscribe(handle) @adapter.unsubscribe(handle) if @adapter.respond_to?(:unsubscribe) end |