Sha256: 04ecad84681aed5ac1f9a6ce076ac3ed57884df268ac13a43694c31dd796da49

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

require 'set'

module RR
  module Integrations
  end

  def self.register_adapter(klass)
    adapter = Integrations::Decorator.new(klass.new)
    unless adapters_by_name.key?(adapter.name)
      adapters << adapter
      adapters_by_name[adapter.name] = adapter
    end
  end

  def self.adapters
    @adapters ||= []
  end

  def self.adapters_by_name
    @adapters_by_name ||= {}
  end

  def self.loaded_adapter_names
    adapters.
      select { |adapter| adapter.loaded? }.
      map { |adapter| adapter.name }
  end

  def self.applicable_adapters
    adapters.select { |adapter| adapter.applies? }
  end

  def self.find_applicable_adapter(name)
    adapters.
      select { |adapter| name === adapter.name.to_s }.
      find   { |adapter| adapter.applies? }
  end

  def self.module_shim_for_adapter(adapter)
    mod = Module.new
    (class << mod; self; end).class_eval do
      define_method(:included) do |base|
        # Note: This assumes that the thing that is including this module
        # is the same that the adapter detected and will hook into.
        adapter.load
      end
    end
    mod
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rr-3.1.1 lib/rr/integrations.rb
rr-3.1.0 lib/rr/integrations.rb
rr-3.0.9 lib/rr/integrations.rb
rr-3.0.8 lib/rr/integrations.rb
rr-3.0.7 lib/rr/integrations.rb
rr-3.0.6 lib/rr/integrations.rb
rr-3.0.5 lib/rr/integrations.rb
rr-3.0.4 lib/rr/integrations.rb
rr-3.0.3 lib/rr/integrations.rb
rr-3.0.2 lib/rr/integrations.rb
rr-3.0.1 lib/rr/integrations.rb
rr-3.0.0 lib/rr/integrations.rb
rr-1.2.1 lib/rr/integrations.rb
rr-1.2.0 lib/rr/integrations.rb
rr-1.1.2 lib/rr/integrations.rb
rr-1.1.2.rc1 lib/rr/integrations.rb