Class: DTK::Network::Client::Config
- Inherits:
-
Object
- Object
- DTK::Network::Client::Config
show all
- Extended by:
- Util::OsUtil
- Defined in:
- lib/client/config.rb
Constant Summary
collapse
- DTK_NETWORK_FILE =
'.dtk_network'
- DTK_NETWORK_CONFIG =
File.join(dtk_local_folder, DTK_NETWORK_FILE)
Util::OsUtil::DTK_HOME_DIR, Util::OsUtil::DTK_MODULES_DIR, Util::OsUtil::DTK_MODULES_GZIP_DIR
Class Method Summary
collapse
current_dir, delim, dtk_local_folder, dtk_modules_gzip_location, dtk_modules_location, home_dir, temp_dir
Class Method Details
.get_credentials ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/client/config.rb', line 10
def self.get_credentials
raise "Dtk network config file (#{DTK_NETWORK_CONFIG}) does not exist" unless File.exists?(DTK_NETWORK_CONFIG)
ret = parse_key_value_file(DTK_NETWORK_CONFIG)
[:email, :password].each{ |k| raise "cannot find #{k}" unless ret[k] }
{
email: ret[:email],
password: ret[:password]
}
end
|
.get_endpoint ⇒ Object
20
21
22
23
24
25
|
# File 'lib/client/config.rb', line 20
def self.get_endpoint
raise "Dtk network config file (#{DTK_NETWORK_CONFIG}) does not exist" unless File.exists?(DTK_NETWORK_CONFIG)
ret = parse_key_value_file(DTK_NETWORK_CONFIG)
[:endpoint, :port].each{ |k| raise "cannot find #{k}" unless ret[k] }
"#{ret[:endpoint]}:#{ret[:port]}"
end
|
.module_download_location ⇒ Object
27
28
29
30
31
32
|
# File 'lib/client/config.rb', line 27
def self.module_download_location
if File.exists?(DTK_NETWORK_CONFIG)
ret = parse_key_value_file(DTK_NETWORK_CONFIG) || {}
ret[:download_location]
end
end
|
.parse_key_value_file(file) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/client/config.rb', line 34
def self.parse_key_value_file(file)
raise "Config file (#{file}) does not exists" unless File.exists?(file)
ret = Hash.new
File.open(file).each do |line|
line.gsub!(/\s*$/, "")
unless line =~ /^#|^$/
if (line =~ /(.+?)\s*=\s*(.+)/)
key = $1
val = $2
ret[key.to_sym] = val
end
end
end
ret
end
|