Class: PipeRpc::Hub::TransportMapper

Inherits:
Mapper show all
Defined in:
lib/pipe_rpc/hub_transport_mapper.rb

Instance Method Summary collapse

Methods inherited from Mapper

#map

Constructor Details

#initialize(gateway) ⇒ TransportMapper

Returns a new instance of TransportMapper.



5
6
7
# File 'lib/pipe_rpc/hub_transport_mapper.rb', line 5

def initialize(gateway)
  @gateway = gateway
end

Instance Method Details

#from_transport(object) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pipe_rpc/hub_transport_mapper.rb', line 19

def from_transport(object)
  map(object) do |value|
    if (value.is_a? String) and (value.start_with? Client::TRANSPORT_PREFIX)
      Server.from_rpc_transport(@gateway, value)
    elsif (value.is_a? String) and (value.start_with? Server::TRANSPORT_PREFIX)
      Client.from_rpc_transport(@gateway, value)
    else
      value
    end
  end
end

#to_transport(object) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/pipe_rpc/hub_transport_mapper.rb', line 9

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