class AdapterRegistry::Registry

Public Instance Methods

get(trait, context) click to toggle source
# File lib/adapter-registry/registry.rb, line 12
def get(trait, context)
  if adapter = get_adapter(trait, context)
    adapter.instance_for(context)
  end
end
get_adapter(trait, context) click to toggle source
# File lib/adapter-registry/registry.rb, line 4
def get_adapter(trait, context)
  if trait_registry = self[trait]
    trait_registry.select do |entry|
      entry[:for].call(context)
    end.map { |entry| entry[:adapter] }.first
  end
end
set(trait, adapter, &block) click to toggle source
# File lib/adapter-registry/registry.rb, line 18
def set(trait, adapter, &block)
  self[trait] ||= Set.new
  self[trait] << {
    adapter: adapter,
    for: block,
  }
end