Class: ZMQMachine::Address
- Inherits:
-
Object
- Object
- ZMQMachine::Address
- Defined in:
- lib/zm/address.rb
Overview
FIXME: needs to handle ipc and inproc transports better, e.g. there is no port component to either one.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Class Method Summary collapse
-
.from_string(string) ⇒ Object
Converts strings with the format “type://host:port” into an Address instance.
Instance Method Summary collapse
-
#initialize(host, port, type = :tcp) ⇒ Address
constructor
type
: :tcp, :pgm or :inprocess. - #to_s ⇒ Object
Constructor Details
#initialize(host, port, type = :tcp) ⇒ Address
type
: :tcp, :pgm or :inprocess
46 47 48 49 50 |
# File 'lib/zm/address.rb', line 46 def initialize host, port, type = :tcp @host = host @port = port @transport = determine_type type end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
43 44 45 |
# File 'lib/zm/address.rb', line 43 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
43 44 45 |
# File 'lib/zm/address.rb', line 43 def port @port end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
43 44 45 |
# File 'lib/zm/address.rb', line 43 def transport @transport end |
Class Method Details
.from_string(string) ⇒ Object
Converts strings with the format “type://host:port” into an Address instance.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zm/address.rb', line 65 def self.from_string string #FIXME: needs error checking and ability to handle inproc/ipc types # # should also return nil or some other error indication when parsing fails split = string.split(':') type = split[0] port = split[2] # nil for ipc/inproc and non-empty for tcp host = split[1].slice(2, split[1].length) #sub('//', '') Address.new host, port, type.downcase.to_sym end |
Instance Method Details
#to_s ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/zm/address.rb', line 52 def to_s case @transport when :tcp "#{@transport}://#{@host}:#{@port}" else "#{@transport}://#{@host}" end end |