Module: Aerospike::Host::Parse
- Defined in:
- lib/aerospike/host/parse.rb
Constant Summary collapse
- INTEGER_REGEX =
/\A\d+\z/
Class Method Summary collapse
-
.call(hosts, default_port = 3000) ⇒ Object
Parse hosts from string format: hostname1[:port1],…
Class Method Details
.call(hosts, default_port = 3000) ⇒ Object
Parse hosts from string format: hostname1[:port1],…
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aerospike/host/parse.rb', line 27 def call(hosts, default_port = 3000) case hosts when Host [hosts] when Array hosts when String hosts.split(?,).map { |host| addr, tls_name, port = host.split(?:) if port.nil? && tls_name && tls_name.match(INTEGER_REGEX) port = tls_name tls_name = nil end port ||= default_port Host.new(addr, port.to_i, tls_name) } else fail TypeError, "hosts should be a Host object, an Array of Host objects, or a String" end end |