Sha256: 24a47df3ca1870319c9e06791fb0030a240cfbb88016114d0cf7027c088fe282

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

$config = {} if not defined? $config
if defined?(CONFIG_FILE) and FileTest.exist?(CONFIG_FILE)
  File.open(CONFIG_FILE) { |f| $config = YAML::load(f).to_sym }
end
$name = $0.match(/.*?([^\/]*).rb/)[1]

def get_config(default, *path)
  get_config_rec(path, default)
end

def get_config_rec(path, default, config = $config)
  if path.length == 0
    return config
  else
    key = path.shift.to_sym
    if config and config.has_key? key
      return get_config_rec(path, default, config[key])
    else
      return default
    end
  end
end

def set_config(value, *path)
  if path.length == 0
    dputs(0) { "Error: empty path in #{caller.inspect}" }
  else
    config = $config
    path[0...-1].each { |p|
      dputs(4) { "Doing level #{p}" }
      if !config.has_key? p
        config[p] = {}
        dputs(4) { "Added Hash to #{p} - #{$config.inspect}" }
      end
      config = config[p]
    }
    config[path.last] = value
    dputs(4) { "config is #{config.inspect} - $config is #{$config.inspect}" }
  end
end

defined?(CONFIG_FILE) and dputs(2) { "config is #{$config.inspect} - file is #{CONFIG_FILE}" }

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qooxview-1.9.10 lib/qooxview/config_yaml.rb
qooxview-1.9.9 lib/qooxview/config_yaml.rb