module ActiveWebhook

Constants

Hook
IDENTIFIER
VERSION

Attributes

enabled[W]

Public Class Methods

configuration() click to toggle source
# File lib/active_webhook.rb, line 35
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/active_webhook.rb, line 39
def configure
  yield(configuration)

  configuration.after_configure
end
disable() { || ... } click to toggle source
# File lib/active_webhook.rb, line 83
def disable
  state = enabled?
  configuration.enabled = false
  value = yield
ensure
  configuration.enabled = state
  value
end
disabled?() click to toggle source
# File lib/active_webhook.rb, line 70
def disabled?
  !enabled?
end
enable() { || ... } click to toggle source
# File lib/active_webhook.rb, line 74
def enable
  state = enabled?
  configuration.enabled = true
  value = yield
ensure
  configuration.enabled = state
  value
end
enabled?() click to toggle source

TODO: change the next 4 methods to use memoized thread safe class var rather than configuration.enabled

# File lib/active_webhook.rb, line 66
def enabled?
  configuration.enabled
end
logger() click to toggle source
# File lib/active_webhook.rb, line 45
def logger
  defined?(Rails) ? Rails.logger : (@logger ||= Logger.new($stdout))
end
origin() click to toggle source
# File lib/active_webhook.rb, line 57
def origin
  return @@origin if defined? @@origin

  @@origin = (Rails.application.config.action_mailer.default_url_options[:host] if defined?(Rails))
rescue StandardError
  @@origin = ""
end
subscription_model() click to toggle source
# File lib/active_webhook.rb, line 49
def subscription_model
  configuration.models.subscription
end
topic_model() click to toggle source
# File lib/active_webhook.rb, line 53
def topic_model
  configuration.models.topic
end
trigger(key:, version: nil, **context) click to toggle source
# File lib/active_webhook.rb, line 98
def trigger(key:, version: nil, **context)
  queueing_adapter.call(key: key, version: version, **context) if enabled?
  true
end

Protected Class Methods

fetch_adapter(type, adapter) click to toggle source
# File lib/active_webhook.rb, line 105
def fetch_adapter(type, adapter)
  if adapter.is_a?(Symbol) || adapter.is_a?(String)
    adapter = begin
      @adapters ||= {}
      @adapters[type] ||= {}
      @adapters[type][adapter.to_sym] = begin
        path = "active_webhook/#{type}/#{adapter}_adapter"
        require path
        const_name = path.camelize
        ["http", "sha", "hmac", "json", "url"].each { |acronym| const_name.gsub!(acronym.camelize, acronym.upcase) }
        const_name.constantize
      end
    end
  end

  raise InvalidAdapterError unless adapter.respond_to?(:call)

  adapter
end