module PipeRpc class Hub::Server < BasicInterface TRANSPORT_PREFIX = "__rpc_server__" kernel = ::Kernel.dup kernel.class_eval do alias_method :__rpc_server_class__, :class (instance_methods - [:__rpc_server_class__, :object_id]).each{ |m| remove_method m } private_instance_methods.each{ |m| remove_method m } if respond_to? :private_instance_methods end include kernel def to_rpc_server_id "#{__rpc_server_class__}##{__id__}".to_sym end def to_rpc_transport(hub) hub.servers.add(self) unless hub.servers.registered? to_rpc_server_id "#{TRANSPORT_PREFIX}#{to_rpc_server_id}" end end class << Hub::Server def const_missing(name) ::Object.const_get(name) end def instance_eval_for(server, *args, &block) Object.instance_method(:instance_eval).bind(server).call(*args, &block) end def from_rpc_transport?(transport) (transport.is_a? String) and (transport.start_with? Client::TRANSPORT_PREFIX) end def from_rpc_transport(hub, transport) hub.servers[transport.sub(Client::TRANSPORT_PREFIX, '').to_sym] end end end