Class: MailgunWebhooks::WebhookRegistry
- Inherits:
-
Object
- Object
- MailgunWebhooks::WebhookRegistry
- Defined in:
- lib/mailgun_webhooks/webhook_registry.rb
Instance Method Summary collapse
-
#initialize ⇒ WebhookRegistry
constructor
A new instance of WebhookRegistry.
-
#on(webhook, &block) ⇒ Object
Public: Store a block by name for later execution.
-
#trigger(webhook, data) ⇒ Object
Public: Execute all of the blocks associated with the webhook.
Constructor Details
#initialize ⇒ WebhookRegistry
Returns a new instance of WebhookRegistry.
4 5 6 |
# File 'lib/mailgun_webhooks/webhook_registry.rb', line 4 def initialize @hooks = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#on(webhook, &block) ⇒ Object
Public: Store a block by name for later execution.
Returns nothing.
11 12 13 |
# File 'lib/mailgun_webhooks/webhook_registry.rb', line 11 def on(webhook, &block) @hooks[webhook.to_sym] << block end |
#trigger(webhook, data) ⇒ Object
Public: Execute all of the blocks associated with the webhook.
Returns nothing.
18 19 20 |
# File 'lib/mailgun_webhooks/webhook_registry.rb', line 18 def trigger(webhook, data) @hooks[webhook.to_sym].each { |hook| hook.call data } end |