Class: Takagi::EventBus::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/takagi/event_bus.rb

Overview

Event handler wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  @address = address
  @block = block
  @options = options
  @local_only = options.fetch(:local_only, false)
  @pool_id = SecureRandom.uuid
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



69
70
71
# File 'lib/takagi/event_bus.rb', line 69

def address
  @address
end

#blockObject (readonly)

Returns the value of attribute block.



69
70
71
# File 'lib/takagi/event_bus.rb', line 69

def block
  @block
end

#optionsObject (readonly)

Returns the value of attribute options.



69
70
71
# File 'lib/takagi/event_bus.rb', line 69

def options
  @options
end

#pool_idObject (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(message)
  @block.call(message)
rescue StandardError => e
  if defined?(Takagi.logger)
    Takagi.logger.error "Event handler error for #{@address}: #{e.message}"
  else
    warn "Event handler error for #{@address}: #{e.message}"
  end
end

#local_only?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/takagi/event_bus.rb', line 89

def local_only?
  @local_only
end