Class: Takagi::EventBus::Handler
- Inherits:
-
Object
- Object
- Takagi::EventBus::Handler
- Defined in:
- lib/takagi/event_bus.rb
Overview
Event handler wrapper
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pool_id ⇒ Object
readonly
Returns the value of attribute pool_id.
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize(address, options = {}, &block) ⇒ Handler
constructor
A new instance of Handler.
- #local_only? ⇒ Boolean
Constructor Details
#initialize(address, options = {}, &block) ⇒ Handler
Returns a new instance of Handler.
71 72 73 74 75 76 77 |
# File 'lib/takagi/event_bus.rb', line 71 def initialize(address, = {}, &block) @address = address @block = block @options = @local_only = .fetch(:local_only, false) @pool_id = SecureRandom.uuid end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
69 70 71 |
# File 'lib/takagi/event_bus.rb', line 69 def address @address end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
69 70 71 |
# File 'lib/takagi/event_bus.rb', line 69 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
69 70 71 |
# File 'lib/takagi/event_bus.rb', line 69 def @options end |
#pool_id ⇒ Object (readonly)
Returns the value of attribute pool_id.
69 70 71 |
# File 'lib/takagi/event_bus.rb', line 69 def pool_id @pool_id end |
Instance Method Details
#call(message) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/takagi/event_bus.rb', line 79 def call() @block.call() rescue StandardError => e if defined?(Takagi.logger) Takagi.logger.error "Event handler error for #{@address}: #{e.}" else warn "Event handler error for #{@address}: #{e.}" end end |
#local_only? ⇒ Boolean
89 90 91 |
# File 'lib/takagi/event_bus.rb', line 89 def local_only? @local_only end |