Sha256: 8ea7df2eeb6bfe77fe1d17277c9473c4079486a8c4b604f2c6ef7be904cc7fd8

Contents?: true

Size: 751 Bytes

Versions: 3

Compression:

Stored size: 751 Bytes

Contents

# frozen_string_literal: true

require 'solidus_webhooks/errors'

module SolidusWebhooks
  class Configuration
    def initialize
      @handlers = {}
    end

    def register_webhook_handler(id, handler)
      unless handler.respond_to? :call
        raise SolidusWebhooks::InvalidHandler,
          "Please provide a handler that responds to #call, got: #{handler.inspect}"
      end

      @handlers[id.to_sym] = handler
    end

    def find_webhook_handler(id)
      @handlers[id.to_sym]
    end
  end

  class << self
    def configuration
      @configuration ||= Configuration.new
    end

    alias config configuration

    def reset_config!
      @configuration = nil
    end

    def configure
      yield configuration
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_webhooks-0.4.2 lib/solidus_webhooks/configuration.rb
solidus_webhooks-0.4.1 lib/solidus_webhooks/configuration.rb
solidus_webhooks-0.4.0 lib/solidus_webhooks/configuration.rb