Class: ActiveWebhook::Queueing::BaseAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/active_webhook/queueing/base_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

attribute, attributes, #attributes, call, component_configuration, #component_configuration, configuration, #configuration, #initialize

Constructor Details

This class inherits a constructor from ActiveWebhook::Adapter

Class Method Details

.build_hook(subscription, **context) ⇒ Object



20
21
22
# 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) ⇒ Object



24
25
26
27
28
29
30
31
# 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

Instance Method Details

#callObject

returns count of jobs enqueued



13
14
15
16
17
18
# File 'lib/active_webhook/queueing/base_adapter.rb', line 13

def call
  return fulfill_topic if format_first

  promise_topic
  1
end

#format_firstObject



8
9
10
# File 'lib/active_webhook/queueing/base_adapter.rb', line 8

def format_first
  @format_first.nil? ? component_configuration.format_first : @format_first
end

#fulfill_topicObject



33
34
35
36
37
38
39
40
# 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