Sha256: 8fecae441527503be2af386ff53754c4a5511c83e8aacd73a3519e94f19d5c9c

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

module PipeRpc
  class Mapper; end
  class Hub::TransportMapper < Mapper
    def initialize(hub)
      @hub = hub
    end

    def to_transport(object)
      map(object) do |value|
        if value.respond_to? :to_rpc_transport
          value.to_rpc_transport(@hub)
        else
          value
        end
      end
    end

    def from_transport(object)
      map(object) do |value|
        if (value.is_a? String) and (value.start_with? Client::TRANSPORT_PREFIX)
          @hub.servers[value.sub(Client::TRANSPORT_PREFIX, '').to_sym]
        elsif (value.is_a? String) and (value.start_with? Server::TRANSPORT_PREFIX)
          @hub.clients[value.sub(Server::TRANSPORT_PREFIX, '').to_sym]
        else
          value
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pipe_rpc-2.4.0 lib/pipe_rpc/hub_transport_mapper.rb