Sha256: e0599dbf27ea01b597d00eda165604db9ceb54de818598df18b24b31f8365ec1

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'set'

module Basquiat
  # base module extend the classes that will use the event infrastructure
  module Base
    class << self
      def extended(klass)
        descendants.push klass
      end

      def descendants
        @descendants ||= []
      end
    end

    def reload_adapter_from_configuration
      @adapter = Kernel.const_get(Basquiat.configuration.default_adapter).new
      @adapter.adapter_options Basquiat.configuration.adapter_options
    end

    def event_adapter=(adapter)
      @adapter = adapter.new
    end

    def adapter
      @adapter ||= Kernel.const_get(Basquiat.configuration.default_adapter).new
    end

    def adapter_options(opts = Basquiat.configuration.adapter_options)
      adapter.adapter_options(opts)
    end

    def publish(event, message)
      adapter.publish(event, message)
    end

    def subscribe_to(event_name, proc)
      proc = make_callable(proc)
      adapter.subscribe_to(event_name, proc)
    end

    def disconnect
      adapter.disconnect
    end

    def connected?
      adapter.connected?
    end

    def listen(block: true)
      adapter.listen(block: block)
    end

    private

    def make_callable(proc)
      return proc if proc.respond_to? :call
      method(proc)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basquiat-1.2.0 lib/basquiat/interfaces/base.rb