Sha256: 957ac1a77dc4e88cb88f10f1b5aad3f49bcbd4176605b4b220edd79da2c9cafc

Contents?: true

Size: 807 Bytes

Versions: 1

Compression:

Stored size: 807 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 === server
        [server.__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

1 entries across 1 versions & 1 rubygems

Version Path
pipe_rpc-2.5.0 lib/pipe_rpc/hub_servers.rb