Class: ParseDecision::Config
- Inherits:
-
KtCfg::CfgFile
- Object
- KtCfg::CfgFile
- ParseDecision::Config
- Defined in:
- lib/parse_decision/config.rb
Overview
Controller class handles interactions bewteen the view (cmdline script) and the model (Tool).
Instance Attribute Summary collapse
-
#cfg ⇒ Object
Returns the value of attribute cfg.
Instance Method Summary collapse
- #addKeyValue(key, value) ⇒ Object
-
#initialize(rootDir = nil) ⇒ Config
constructor
A new instance of Config.
-
#load ⇒ Object
Load the YAML configuration file.
-
#save(cfg = nil) ⇒ Object
Save the @cfg hash to a YAML file.
- #setDefaults ⇒ Object
Constructor Details
#initialize(rootDir = nil) ⇒ Config
Returns a new instance of Config.
24 25 26 27 28 29 30 |
# File 'lib/parse_decision/config.rb', line 24 def initialize(rootDir=nil) $LOG.debug "Config::initialize" super @cfg = {} setDefaults() end |
Instance Attribute Details
#cfg ⇒ Object
Returns the value of attribute cfg.
22 23 24 |
# File 'lib/parse_decision/config.rb', line 22 def cfg @cfg end |
Instance Method Details
#addKeyValue(key, value) ⇒ Object
85 86 87 88 |
# 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 ⇒ Object
Load the YAML configuration file.
- returns
-
a hash containing configuration info.
64 65 66 67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
Save the @cfg hash to a YAML file.
77 78 79 80 81 82 83 |
# 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 ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |