class DTK::Network::Client::Config

Constants

DTK_NETWORK_CONFIG
DTK_NETWORK_FILE

Public Class Methods

get_credentials() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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|
    # strip blank spaces, tabs etc off the end of all lines
    line.gsub!(/\s*$/, "")
    unless line =~ /^#|^$/
      if (line =~ /(.+?)\s*=\s*(.+)/)
        key = $1
        val = $2
        ret[key.to_sym] = val
      end
    end
  end

  ret
end