Module: Torpedo::Config

Defined in:
lib/torpedo/config.rb

Constant Summary collapse

@@configs =
nil

Class Method Summary collapse

Class Method Details

.load_configsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/torpedo/config.rb', line 8

def self.load_configs
  return @@configs if not @@configs.nil?

  config_file=ENV['TORPEDO_CONFIG_FILE']
  if config_file.nil? then

    config_file=ENV['HOME']+File::SEPARATOR+".torpedo.conf"
    if not File.exists?(config_file) then
      config_file="/etc/torpedo.conf"
    end

  end

  if File.exists?(config_file) then
    configs = YAML.load_file(config_file) || {}
    @@configs = configs
  else
    raise "Failed to load torpedo config file. Please configure /etc/torpedo.conf or create a .torpedo.conf config file in your HOME directory."
  end

  @@configs

end

.raise_if_nil_or_empty(options, key) ⇒ Object



32
33
34
35
36
# File 'lib/torpedo/config.rb', line 32

def self.raise_if_nil_or_empty(options, key)
  if not options or options[key].nil? or options[key].empty? then
    raise "Please specify a valid #{key.to_s} parameter."
  end
end