module PipeRpc class Hub::Servers def initialize @servers = Hash.new{ |hash, key| raise NoServerError.new("no server #{key}") } end def add(server) id, server = if server.respond_to? :to_rpc_server_id [server.to_rpc_server_id, server] else server.first end if registered? id raise ServerRegistrationError.new("server id #{id.inspect} already used for another server") else @servers[id] = server end end def [](id) @servers[id.to_sym] end def remove(id) @servers.delete(id.to_sym) end def registered?(id) @servers.has_key?(id) end end end