Sha256: df0231ec8ad6b26ffdd48beb231dca0ca59dd7ea790f95afc02a9e9929e6c070

Contents?: true

Size: 894 Bytes

Versions: 4

Compression:

Stored size: 894 Bytes

Contents

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

      def servers
        @servers.dup
      end

      def add_server(servers)
        servers.each{ |name, server| @servers[name.to_sym] = server }
      end

      def rmv_server(server_name)
        @servers.delete(server_name.to_sym)
      end

      def on_request(&on_request)
        @on_request = on_request
      end

      def handle_notification(notification)
        handle_request(notification)
      end

      def handle_request(request)
        @on_request.call(request.server, request.method, request.arguments) if @on_request
        Request.new(self, request).handle
      end

      def send_response(response)
        @hub.send_response response
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pipe_rpc-0.3.2 lib/pipe_rpc/hub/responder.rb
pipe_rpc-0.3.1 lib/pipe_rpc/hub/responder.rb
pipe_rpc-0.3.0 lib/pipe_rpc/hub/responder.rb
pipe_rpc-0.2.2 lib/pipe_rpc/hub/responder.rb