Class: MailgunWebhooks::WebhookRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun_webhooks/webhook_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeWebhookRegistry

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