class NormalizeXml::Config

Attributes

cfg[RW]
cfgFile[W]

Public Class Methods

new(rootDir=nil) click to toggle source
Calls superclass method
# File lib/normalizexml/config.rb, line 22
def initialize(rootDir=nil)
  $LOG.debug "Config::initialize"
  super
  @cfg = {}

  setDefaults()
end

Public Instance Methods

load() click to toggle source

Load the YAML configuration file.

returns

a hash containing configuration info.

# File lib/normalizexml/config.rb, line 75
def load
  $LOG.debug "Config::load"
  tmpCfg = read(@cfgFile)
  @cfg = tmpCfg if !tmpCfg.nil? && !tmpCfg.empty?
  @cfg
end
save() click to toggle source

Save the @cfg hash to a YAML file.

# File lib/normalizexml/config.rb, line 84
def save
  $LOG.debug "Config::save"
  write(@cfgFile, @cfg)
end
setDefaults() click to toggle source
# File lib/normalizexml/config.rb, line 31
def setDefaults
  $LOG.debug "Config::setDefaults"

  # Notes about APPDATA paths:
  # Local app data should be used when an app's data is too
  # big to move around. Or is specific to the machine running
  # the application.
  #
  # Roaming app data files could be pushed to a server (in a
  # domain environment) and downloaded onto a different work
  # station.
  #
  # LocalLow is used for data that must be sandboxed. Currently
  # it is only used by IE for addons and storing data from
  # untrusted sources (as far as I know).
  #


  appDataPath = ENV["APPDATA"]          # APPDATA returns AppData\Roaming on Vista/W7
  appDataPath ||= ENV["HOME"]          # APPDATA returns AppData\Roaming on Vista/W7
  #appDataPath = ENV["LOCALAPPDATA"]        # LOCALAPPDATA returns AppData\Local on Vista/W7
  appDataPath = File.rubypath(File.join(appDataPath, "normalizexml"))
  @cfg[:appPath] = appDataPath
  @cfg[:version]  = NormalizeXml::VERSION
  @cfg[:logging]  = false

  @cfgFile = "normalizexml.yml"

  # Set the config file path. Default is the 'global' one in APPDATA.
  if( @rootDir.nil? )
    @rootDir = appDataPath
    @cfgFile = "config.yml"

    # Override the gobal config if there is a local (current working dir) version.
    if(File.exists?(File.join(FileUtils.pwd(), "normalizexml.yml")))
      @rootDir = FileUtils.pwd()
      @cfgFile = "normalizexml.yml"
    end
  end
end