Class: PipeRpc::Hub::Servers
Instance Method Summary collapse
- #[](id) ⇒ Object
- #add(server) ⇒ Object
-
#initialize ⇒ Servers
constructor
A new instance of Servers.
- #registered?(id) ⇒ Boolean
- #registered_ids ⇒ Object
- #remove(id) ⇒ Object
Constructor Details
#initialize ⇒ Servers
Returns a new instance of Servers.
3 4 5 |
# File 'lib/pipe_rpc/hub_servers.rb', line 3 def initialize @servers = Hash.new{ |hash, key| raise NoServerError.new("no server #{key.inspect}") } end |
Instance Method Details
#[](id) ⇒ Object
31 32 33 |
# File 'lib/pipe_rpc/hub_servers.rb', line 31 def [](id) @servers[id] end |
#add(server) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pipe_rpc/hub_servers.rb', line 7 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 |
#registered?(id) ⇒ Boolean
23 24 25 |
# File 'lib/pipe_rpc/hub_servers.rb', line 23 def registered?(id) @servers.has_key?(id) end |
#registered_ids ⇒ Object
27 28 29 |
# File 'lib/pipe_rpc/hub_servers.rb', line 27 def registered_ids @servers.keys end |
#remove(id) ⇒ Object
35 36 37 |
# File 'lib/pipe_rpc/hub_servers.rb', line 35 def remove(id) @servers.delete(id) end |