Class: NtiEventBus::HandlerBase
- Inherits:
-
Object
- Object
- NtiEventBus::HandlerBase
- Defined in:
- lib/nti_event_bus/handler_base.rb
Overview
Base class for all event handlers.
A handler lives inside the subscribing module and is responsible for:
1. Extracting what it needs from the raw event payload
2. Doing any lookups / transformations
3. Calling the module's Main interactor (or service) with normalized params
Subclasses must implement #call.
Example:
class CreateAuditLog::Handlers::OrderVoided < NtiEventBus::HandlerBase
def call
CreateAuditLog::Main.call(
cashier_id: payload.fetch(:cashier_id),
...
)
end
end
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(payload) ⇒ HandlerBase
constructor
A new instance of HandlerBase.
Constructor Details
#initialize(payload) ⇒ HandlerBase
Returns a new instance of HandlerBase.
27 28 29 |
# File 'lib/nti_event_bus/handler_base.rb', line 27 def initialize(payload) @payload = payload.with_indifferent_access.freeze end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
25 26 27 |
# File 'lib/nti_event_bus/handler_base.rb', line 25 def payload @payload end |
Instance Method Details
#call ⇒ Object
31 32 33 |
# File 'lib/nti_event_bus/handler_base.rb', line 31 def call raise NotImplementedError, "#{self.class}#call must be implemented" end |