class Lucid::Shopify::WebhookHandlerList
Public Class Methods
new()
click to toggle source
# File lib/lucid/shopify/webhook_handler_list.rb, line 6 def initialize @handlers = {} end
Public Instance Methods
[](topic)
click to toggle source
@param topic [String]
# File lib/lucid/shopify/webhook_handler_list.rb, line 27 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 34 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 15 def register(topic, handler = nil, &block) raise ArgumentError unless nil ^ handler ^ block handler = block if block @handlers[topic] ||= [] @handlers[topic] << handler nil end