Class: Hooksmith::Dispatcher
- Inherits:
-
Object
- Object
- Hooksmith::Dispatcher
- Defined in:
- lib/hooksmith/dispatcher.rb
Overview
Dispatcher routes incoming webhook payloads to the appropriate processor.
Uses string keys internally to prevent Symbol DoS attacks when processing untrusted webhook input from external sources.
Instance Attribute Summary collapse
-
#event ⇒ String
readonly
The event name.
-
#payload ⇒ Hash
readonly
The webhook payload.
-
#provider ⇒ String
readonly
The provider name.
Instance Method Summary collapse
-
#initialize(provider:, event:, payload:) ⇒ Dispatcher
constructor
Initializes a new Dispatcher.
-
#run! ⇒ Object?
Runs the dispatcher.
Constructor Details
#initialize(provider:, event:, payload:) ⇒ Dispatcher
Initializes a new Dispatcher.
25 26 27 28 29 |
# File 'lib/hooksmith/dispatcher.rb', line 25 def initialize(provider:, event:, payload:) @provider = provider.to_s @event = event.to_s @payload = payload end |
Instance Attribute Details
#event ⇒ String (readonly)
Returns the event name.
16 17 18 |
# File 'lib/hooksmith/dispatcher.rb', line 16 def event @event end |
#payload ⇒ Hash (readonly)
Returns the webhook payload.
18 19 20 |
# File 'lib/hooksmith/dispatcher.rb', line 18 def payload @payload end |
#provider ⇒ String (readonly)
Returns the provider name.
14 15 16 |
# File 'lib/hooksmith/dispatcher.rb', line 14 def provider @provider end |
Instance Method Details
#run! ⇒ Object?
Runs the dispatcher.
Instantiates each processor registered for the given provider and event, then selects the ones that can handle the payload using the can_handle? method.
- If no processors qualify, logs a warning (or raises NoProcessorError in strict mode).
- If more than one qualifies, raises MultipleProcessorsError.
- Otherwise, processes the event with the single matching processor.
43 44 45 46 47 |
# File 'lib/hooksmith/dispatcher.rb', line 43 def run! Hooksmith::Instrumentation.instrument('dispatch', provider: @provider, event: @event) do dispatch_webhook end end |