Class: Lucid::Shopify::WebhookHandlerList
- Inherits:
-
Object
- Object
- Lucid::Shopify::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.
6 7 8 |
# File 'lib/lucid/shopify/webhook_handler_list.rb', line 6 def initialize @handlers = {} end |
Instance Method Details
#[](topic) ⇒ Object
27 28 29 |
# File 'lib/lucid/shopify/webhook_handler_list.rb', line 27 def [](topic) @handlers[topic] || [] end |
#delegate(webhook) ⇒ Object
Call each of the handlers registered for the given topic in turn.
34 35 36 |
# File 'lib/lucid/shopify/webhook_handler_list.rb', line 34 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 Lucid::Shopify::Webhook argument.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lucid/shopify/webhook_handler_list.rb', line 15 def register(topic, handler = nil, &block) raise ArgumentError unless nil ^ handler ^ block handler = block if block @handlers[topic] ||= [] @handlers[topic] << handler nil end |