Class: ConfigResolver
- Inherits:
-
Object
show all
- Defined in:
- lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb
Overview
frozen_string_literal: true
Class Method Summary
collapse
Class Method Details
.build_connection_data(host_value) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 16
def self.build_connection_data(host_value)
if host_value.nil? || host_value.strip.empty?
return nil end
hv = host_value.strip
lower = hv.downcase
if %w[inmemory in-memory].include?(lower)
return nil end
return WsConnectionData.new(hv) if lower.start_with?('ws://') || lower.start_with?('wss://')
if lower.start_with?('tcp://')
begin
return ConfigResolver.parse_tcp(hv[6..-1])
rescue StandardError
return nil end
end
colon = hv.index(':')
if colon && colon > 0 && colon < hv.length - 1
port_part = hv[colon + 1..-1]
slash = port_part.index('/')
port_part = port_part[0...slash] if slash && slash >= 0
begin
port = Integer(port_part)
host_only = hv[0...colon]
unless host_only.strip.empty?
begin
return TcpConnectionData.new(host_only, port)
rescue StandardError
return nil end
end
rescue StandardError
end
end
nil end
|
.parse_tcp(address) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 61
def self.parse_tcp(address)
slash = address.index('/')
host_port = slash && slash >= 0 ? address[0...slash] : address
colon = host_port.rindex(':')
raise 'Invalid tcp:// format.' if !colon || colon <= 0 || colon >= host_port.length - 1
host = host_port[0...colon]
port_str = host_port[colon + 1..-1]
begin
port = Integer(port_str)
rescue StandardError
raise 'Invalid port in tcp:// address.'
end
TcpConnectionData.new(host, port)
end
|
.try_parse_runtime(runtime) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 9
def self.try_parse_runtime(runtime)
raise 'Runtime string cannot be null or whitespace.' if runtime.nil? || runtime.strip.empty?
runtime = runtime.strip.downcase
RuntimeNameHandler.get_runtime(runtime)
end
|