Class: LucidShopify::WebhookHandlerList
- Inherits:
-
Object
- Object
- LucidShopify::WebhookHandlerList
- Defined in:
- lib/lucid_shopify/webhook_handler_list.rb
Instance Method Summary collapse
- #[](topic) ⇒ Object
-
#delegate(webhook) ⇒ Object
Call each of the handlers registered for the given topic in turn.
-
#initialize ⇒ WebhookHandlerList
constructor
A new instance of WebhookHandlerList.
-
#register(topic, handler = nil, &block) ⇒ Object
Register a handler for a webhook topic.
Constructor Details
#initialize ⇒ WebhookHandlerList
Returns a new instance of WebhookHandlerList.
5 6 7 |
# File 'lib/lucid_shopify/webhook_handler_list.rb', line 5 def initialize @handlers = {} end |
Instance Method Details
#[](topic) ⇒ Object
30 31 32 |
# File 'lib/lucid_shopify/webhook_handler_list.rb', line 30 def [](topic) @handlers[topic] || [] end |
#delegate(webhook) ⇒ Object
Call each of the handlers registered for the given topic in turn.
39 40 41 |
# File 'lib/lucid_shopify/webhook_handler_list.rb', line 39 def delegate(webhook) self[webhook.topic].each { |handler| handler.(webhook) } end |
#register(topic, handler = nil, &block) ⇒ Object
Register a handler for a webhook topic. The callable handler should receive a single LucidShopify::Webhook argument.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lucid_shopify/webhook_handler_list.rb', line 16 def register(topic, handler = nil, &block) raise ArgumentError unless nil ^ handler ^ block handler = block if block @handlers[topic] ||= [] @handlers[topic] << handler nil end |