Class: RBus::Transport
- Inherits:
-
Object
- Object
- RBus::Transport
- Defined in:
- lib/rbus/bus/transport.rb
Overview
Transport represents the connection to the bus, and supports sending and recieving messages The class itself is a factory that returns the appropriate transport for an address
Defined Under Namespace
Classes: AbstractTransport, TCPTransport, UNIXTransport
Class Method Summary collapse
- .connect(address) ⇒ Object
-
.parse_address(address) ⇒ Object
Parse a valid connection address.
-
.unescape(value) ⇒ Object
Unescape simple hex encoding (%XX) for values.
Class Method Details
.connect(address) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rbus/bus/transport.rb', line 108 def connect(address) connection_info = parse_address(address) klass = case connection_info['transport'] when 'unix' UNIXTransport when 'tcp' TCPTransport else raise InvalidTransportException, "Unknown transport #{connection_info['transport']}" end klass::new(connection_info) end |
.parse_address(address) ⇒ Object
Parse a valid connection address
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rbus/bus/transport.rb', line 93 def self.parse_address(address) connection_info = {} connection_info['transport'], info = address.split(':', 2) raise InvalidAddressException if info.nil? || info.empty? info.split(',').each do |pair| key, value = pair.split('=') connection_info[key] = unescape(value) end connection_info end |
.unescape(value) ⇒ Object
Unescape simple hex encoding (%XX) for values
88 89 90 |
# File 'lib/rbus/bus/transport.rb', line 88 def self.unescape(value) value.gsub(/%([[:xdigit:]]{2})/) {$1.hex.chr} end |