class Pay::Webhooks::Delegator
Attributes
backend[R]
Public Class Methods
new()
click to toggle source
# File lib/pay/webhooks/delegator.rb, line 6 def initialize @backend = ActiveSupport::Notifications end
Public Instance Methods
all(callable = nil, &block)
click to toggle source
Listen to all events
# File lib/pay/webhooks/delegator.rb, line 23 def all(callable = nil, &block) callable ||= block subscribe nil, callable end
configure() { |self| ... }
click to toggle source
Configure DSL
# File lib/pay/webhooks/delegator.rb, line 11 def configure(&block) raise ArgumentError, "must provide a block" unless block block.arity.zero? ? instance_eval(&block) : yield(self) end
instrument(event:, type:)
click to toggle source
Called to process an event
# File lib/pay/webhooks/delegator.rb, line 34 def instrument(event:, type:) backend.instrument name_with_namespace(type), event end
listening?(type)
click to toggle source
# File lib/pay/webhooks/delegator.rb, line 38 def listening?(type) backend.notifier.listening? name_with_namespace(type) end
subscribe(name, callable = nil, &block)
click to toggle source
Subscribe to specific events
# File lib/pay/webhooks/delegator.rb, line 17 def subscribe(name, callable = nil, &block) callable ||= block backend.subscribe to_regexp(name), NotificationAdapter.new(callable) end
unsubscribe(name)
click to toggle source
Unsubscribe
# File lib/pay/webhooks/delegator.rb, line 29 def unsubscribe(name) backend.unsubscribe name end
Private Instance Methods
name_with_namespace(name, delimiter: ".")
click to toggle source
# File lib/pay/webhooks/delegator.rb, line 60 def name_with_namespace(name, delimiter: ".") [:pay, name].join(delimiter) end
to_regexp(name)
click to toggle source
# File lib/pay/webhooks/delegator.rb, line 56 def to_regexp(name) %r{^#{Regexp.escape name_with_namespace(name)}} end