1. In practice you almost never want to load a random library that says it supports a certain interface, you will want a specific library. Notable exceptions are glibc where the interfaces are well-defined over several decades but that brings us to...
2. Few libraries implement the same exact interface. Mongrel and Unicorn have totally different interfaces. Phusion Passenger is also a web server but works in a fundamentally different way from either of them. Hpricot and Nokogiri are both XML parsers but their usage API is different.
class Mongrel::HttpServer
class HttpServerProtocolAdapter < Gem::ProtocolAdapter
implements 'http-server'
implements 'http-server/with-middleware-support'
...
and the manifests (which would then look more like this:) {'http-server' => Mongrel::HttpServer::HttpServerProtocolAdapter,
'http-server/with-middleware-support' => Mongrel::HttpServer::HttpServerProtocolAdapter,
...}
would be generated automatically at gem installation by loading the gem and then probing for ProtocolAdapter instances in ObjectSpace.Of course, if you had a class that matched the protocol exactly, you could just use something like
class Mongrel::HttpServer
supports_protocol 'http-server'
end
and be done with it.This is all assuming that we don't actually want our protocols to be modules or classes or something else that we have to include in the adapter somehow (because this is Ruby, and we do well without needing IDuck.) Instead, protocols would just be externally specified things, with their name-strings perhaps being the URIs of standards docs. At most, if a Gem::Protocol was a reified type, it would be a unit test suite to determine whether a ProtocolAdapter actually supported its protocol (minimally, via a series of #respond_to?s.)
As an example, their proposed HTTP interface can be found here:
No, but perhaps we could have:
where each rubygem installed has a table of protocols each of its classes and modules support. For example, Mongrel would have a table that starts: