Sha256: e17e787c79e70fb639e414cf20b43b549bfc2513d1a1343280bdf2360fc78b6a

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'delegate'
require 'basquiat/adapters/base_message'

module Basquiat
  module Adapters
    # Base implementation for an adapter
    class Base
      using Basquiat::HashRefinements

      class << self
        def strategies
          @strategies ||= {}
        end

        def register_strategy(config_name, klass)
          strategies.merge!(config_name.to_sym => klass)
        end
      end

      def initialize
        @options = base_options
        @procs   = {}
        @retries = 0
      end

      def strategies
        self.class.strategies
      end

      # Used to set the options for the adapter. It is merged in
      # to the default_options hash.
      # @param [Hash] opts an adapter dependant hash of options
      def adapter_options(opts)
        @options.deep_merge(opts)
      end

      # Default options for the adapter
      # @return [Hash]
      def base_options
        default_options.merge(Basquiat.configuration.adapter_options)
      end

      def default_options
        {}
      end

      def publish
        fail Basquiat::Errors::SubclassResponsibility
      end

      def subscribe_to
        fail Basquiat::Errors::SubclassResponsibility
      end

      def disconnect
        fail Basquiat::Errors::SubclassResponsibility
      end

      private

      attr_reader :procs, :options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basquiat-1.2.0 lib/basquiat/adapters/base_adapter.rb