class ParseDecision::Config

Controller class handles interactions bewteen the view (cmdline script) and the model (Tool).

Attributes

cfg[RW]

Public Class Methods

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

  setDefaults()
end

Public Instance Methods

addKeyValue(key, value) click to toggle source
# File lib/parse_decision/config.rb, line 85
def addKeyValue(key, value)
  $LOG.debug "Config::addKeyValue( #{key.to_s}, #{value} )"
  @cfg[key] = value
end
load() click to toggle source

Load the YAML configuration file.

returns

a hash containing configuration info.

# File lib/parse_decision/config.rb, line 64
def load
  $LOG.debug "Config::load"

  filepath = cfgFilePath("pdconfig.yml")
  if(!File.exists?( filepath ))   # TODO: This needs to be moved into KtCfg.
    $LOG.debug "Config file does not exist. Returning default config obj."
    return @cfg
  end

  @cfg = read("pdconfig.yml")
end
save(cfg=nil) click to toggle source

Save the @cfg hash to a YAML file.

# File lib/parse_decision/config.rb, line 77
def save(cfg=nil)
  $LOG.debug "Config::save( cfg )"
  if( nil != cfg )
    @cfg = cfg
  end
  write("pdconfig.yml", @cfg)
end
setDefaults() click to toggle source
# File lib/parse_decision/config.rb, line 32
def setDefaults
  $LOG.debug "Config::setDefaults"

  # Blow away the existing cfg hash
  @cfg = {}

  # 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["LOCALAPPDATA"]       # LOCALAPPDATA returns AppData\Local on Vista/W7
  appDataPath   ||= ENV["HOME"]
  @cfg[:appPath]  = File.rubypath(File.join(appDataPath, "parse_decision"))
  @cfg[:version]  = ParseDecision::VERSION
  @cfg[:file]   = "2.decision.txt"
  @cfg[:logging]  = false
end