Sha256: 6f2355f97f8653169a686523dc900bf258eca30e69f50844df4eca89b81d4a69

Contents?: true

Size: 825 Bytes

Versions: 4

Compression:

Stored size: 825 Bytes

Contents

module PipeRpc
  class Hub::Servers
    def initialize
      @servers = Hash.new{ |hash, key| raise NoServerError.new("no server #{key.inspect}") }
    end

    def add(server)
      id, server = if server.respond_to? :to_rpc_server_id
        [server.to_rpc_server_id, server]
      else
        server.first
      end

      raise ServerRegistrationError.new("server id #{id.inspect} no symbol") unless id.is_a? Symbol

      if registered? id
        raise ServerRegistrationError.new("server id #{id.inspect} already used for another server")
      else
        @servers[id] = server
      end
    end

    def registered?(id)
      @servers.has_key?(id)
    end

    def registered_ids
      @servers.keys
    end

    def [](id)
      @servers[id]
    end

    def remove(id)
      @servers.delete(id)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pipe_rpc-2.3.0 lib/pipe_rpc/hub_servers.rb
pipe_rpc-2.2.3 lib/pipe_rpc/hub_servers.rb
pipe_rpc-2.2.2 lib/pipe_rpc/hub_servers.rb
pipe_rpc-2.2.1 lib/pipe_rpc/hub_servers.rb