class LucidShopify::WebhookHandlerList
Public Class Methods
new()
click to toggle source
# File lib/lucid_shopify/webhook_handler_list.rb, line 5 def initialize @handlers = {} end
Public Instance Methods
[](topic)
click to toggle source
@param topic [String]
# File lib/lucid_shopify/webhook_handler_list.rb, line 30 def [](topic) @handlers[topic] || [] end
delegate(webhook)
click to toggle source
Call each of the handlers registered for the given topic in turn.
@param webhook [Webhook]
# 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)
click to toggle source
Register a handler for a webhook topic. The callable handler should receive a single {Webhook} argument.
@param topic [String] @param handler [#call]
# 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