Class: Hypertube::Sdk::Tools::JsonFileResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ JsonFileResolver

Returns a new instance of JsonFileResolver.



8
9
10
11
12
13
14
15
16
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 8

def initialize(path)
  @path = path
  begin
    file = File.read(@path)
    @json_object = JSON.parse(file)
  rescue Errno::ENOENT
    raise "Configuration file #{@path} not found. Please check your configuration file."
  end
end

Instance Method Details

#get_channel(runtime_name, config_name) ⇒ Object



39
40
41
42
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 39

def get_channel(runtime_name, config_name)
  runtime = get_runtime(runtime_name, config_name)
  runtime["channel"] || (raise "Channel key not found in configuration file for config #{config_name}. Please check your configuration file.")
end

#get_channel_host(runtime_name, config_name) ⇒ Object



49
50
51
52
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 49

def get_channel_host(runtime_name, config_name)
  channel = get_channel(runtime_name, config_name)
  channel["host"] || (raise "Channel host not found in configuration file for config #{config_name}. Please check your configuration file.")
end

#get_channel_type(runtime_name, config_name) ⇒ Object



44
45
46
47
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 44

def get_channel_type(runtime_name, config_name)
  channel = get_channel(runtime_name, config_name)
  channel["type"] || (raise "Channel type not found in configuration file for config #{config_name}. Please check your configuration file.")
end

#get_license_keyObject



18
19
20
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 18

def get_license_key
  @json_object["licenseKey"] || (raise "License key not found in configuration file. Please check your configuration file.")
end

#get_modules(runtime_name, config_name) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 54

def get_modules(runtime_name, config_name)
  runtime = get_runtime(runtime_name, config_name)
  if runtime.key?('modules')
    return runtime['modules']
  end
  ""
end

#get_runtime(runtime_name, config_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 26

def get_runtime(runtime_name, config_name)
  runtimes = get_runtimes
  if runtimes.key?(runtime_name)
    runtime = runtimes[runtime_name]
    if runtime.is_a?(Array)
      return runtime.find { |item| item["name"] == config_name }
    elsif runtime["name"] == config_name
      return runtime
    end
  end
  raise "Runtime config #{config_name} not found in configuration file for runtime #{runtime_name}. Please check your configuration file."
end

#get_runtimesObject



22
23
24
# File 'lib/hypertube-ruby-sdk/sdk/tools/json_file_resolver.rb', line 22

def get_runtimes
  @json_object["runtimes"]
end