Class: JsonFileResolver

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ JsonFileResolver

Returns a new instance of JsonFileResolver.



5
6
7
8
9
10
11
12
13
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 5

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



36
37
38
39
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 36

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



46
47
48
49
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 46

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_port(runtime_name, config_name) ⇒ Object



51
52
53
54
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 51

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

#get_channel_type(runtime_name, config_name) ⇒ Object



41
42
43
44
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 41

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



15
16
17
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 15

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

#get_runtime(runtime_name, config_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/javonet-ruby-sdk/sdk/tools/json_file_resolver.rb', line 23

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



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

def get_runtimes
  @json_object["runtimes"]
end