Sha256: 81af266f160384eb25abe7293af38a4acdbb83359f6882ab887ae666cb76f051

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module PipeRpc
  class Client < BasicInterface
    TRANSPORT_PREFIX = "__rpc_client__"

    undef_method :instance_eval

    def initialize(server_id = :default, hub)
      Kernel.raise ClientInitializationError.new("server id #{server_id.inspect} no symbol") unless server_id.is_a? Symbol
      @__rpc_server_id__ = server_id
      @__rpc_server_class_name__ = server_id.to_s.split('#').first
      @hub = hub
    end

    attr_reader :__rpc_server_class_name__, :__rpc_server_id__

    def respond_to?(*args)
      super or method_missing(:respond_to?, *args)
    end

    def method_missing(method, *args)
      request = Client::Request.new(@hub, server: @__rpc_server_id__, method: method, arguments: args)
      @hub.requests.evaluate(request)
    end

    def to_rpc_transport(gateway)
      "#{TRANSPORT_PREFIX}#{@__rpc_server_id__}"
    end
  end

  class << Client
    def from_rpc_transport(gateway, transport)
      client = gateway.clients[transport.sub(Server::TRANSPORT_PREFIX, '').to_sym]
      ClientWrapper.from_rpc_transport(gateway, client)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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