Class: ConfigResolver

Inherits:
Object
  • 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



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
# File 'lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 17

def self.build_connection_data(host_value)
  if host_value.nil? || host_value.strip.empty?
    raise 'Host value cannot be null or whitespace.'
  end

  hv = host_value.strip
  lower = hv.downcase

  if %w[inmemory in-memory].include?(lower)
    return nil  # In-memory connection
  end

  return WsConnectionData.new(hv) if lower.start_with?('ws://') || lower.start_with?('wss://')

  # Http2 URL (http:// or https:// ends with h2)
  if((lower.start_with?('http://') && lower.end_with?('h2')) || (lower.start_with?('https://') && lower.end_with?('h2')))
    return Http2ConnectionData.new(hv)
  end

  if lower.start_with?('tcp://') || hv.include?(':')
    return TcpConnectionData.new(hv)
  end

  raise "Host value '#{hv}' is not a recognized connection format."
end

.try_parse_runtime(runtime) ⇒ Object



10
11
12
13
14
15
# File 'lib/hypertube-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 10

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