class ActiveWebhook::Queueing::BaseAdapter

Public Class Methods

build_hook(subscription, **context) click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 20
def self.build_hook(subscription, **context)
  ActiveWebhook.formatting_adapter.call(subscription: subscription, **context)
end
fulfill_subscription(subscription:, hook: nil, **context) click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 24
def self.fulfill_subscription(subscription:, hook: nil, **context)
  ActiveWebhook.delivery_adapter.call(
    subscription: subscription,
    hook: hook || build_hook(subscription, **context),
    **context
  ) if ActiveWebhook.enabled?
  true
end

Protected Class Methods

component_name() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 44
def self.component_name
  "queueing"
end

Public Instance Methods

call() click to toggle source

returns count of jobs enqueued

# File lib/active_webhook/queueing/base_adapter.rb, line 13
def call
  return fulfill_topic if format_first

  promise_topic
  1
end
format_first() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 8
def format_first
  @format_first.nil? ? component_configuration.format_first : @format_first
end
fulfill_topic() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 33
def fulfill_topic
  subscriptions.each do |subscription|
    hook = format_first ? self.class.build_hook(subscription, **context) : nil
    byebug if context.key?("key")
    promise_subscription subscription: subscription, hook: hook
  end
  subscriptions.count
end

Protected Instance Methods

promise_subscription(_subscription:, _hook:) click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 48
def promise_subscription(_subscription:, _hook:)
  raise NotImplementedError, "#promise_subscription must be implemented."
end
promise_topic() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 52
def promise_topic
  raise NotImplementedError, "#promise_topic must be implemented."
end
subscriptions() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 56
def subscriptions
  subscriptions_scope.all
end
subscriptions_scope() click to toggle source
# File lib/active_webhook/queueing/base_adapter.rb, line 60
def subscriptions_scope
  ActiveWebhook.subscription_model.enabled.joins(:topic).includes(:topic).merge(
    ActiveWebhook.topic_model.enabled.with_key(key: key, version: version)
  )
end