Class: KtCfg::CfgFile
- Inherits:
-
Object
- Object
- KtCfg::CfgFile
- Defined in:
- lib/ktcommon/ktcfg.rb
Instance Attribute Summary collapse
-
#rootDir ⇒ Object
Returns the value of attribute rootDir.
Instance Method Summary collapse
- #cfgFilePath(filename) ⇒ Object
-
#initialize(rootDir = nil) ⇒ CfgFile
constructor
A new instance of CfgFile.
- #read(filename) ⇒ Object
- #write(filename, cfg) ⇒ Object
Constructor Details
#initialize(rootDir = nil) ⇒ CfgFile
Returns a new instance of CfgFile.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ktcommon/ktcfg.rb', line 22 def initialize(rootDir = nil) $LOG.debug "CfgFile::initialize" @rootDir = rootDir if( rootDir ) @rootDir = File.rubypath(@rootDir) if( !File.exists?(@rootDir)) $LOG.debug "Creating directory: #{@rootDir}" FileUtils.mkdir(@rootDir) end end end |
Instance Attribute Details
#rootDir ⇒ Object
Returns the value of attribute rootDir.
19 20 21 |
# File 'lib/ktcommon/ktcfg.rb', line 19 def rootDir @rootDir end |
Instance Method Details
#cfgFilePath(filename) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ktcommon/ktcfg.rb', line 41 def cfgFilePath(filename) $LOG.debug "CfgFile::cfgFilePath( #{filename} )" filepath = filename if( @rootDir ) filepath = File.join(@rootDir, filename) end $LOG.debug "Filepath: #{filepath}" filepath end |
#read(filename) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ktcommon/ktcfg.rb', line 63 def read(filename) $LOG.debug "CfgFile::read" filepath = cfgFilePath(filename) cfg = {} if(File.exists?(filepath)) open(filepath) { |f| cfg = YAML.load(f) } end cfg end |
#write(filename, cfg) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/ktcommon/ktcfg.rb', line 52 def write(filename, cfg) $LOG.debug "CfgFile::write" $LOG.debug "Config File Contents: #{cfg.inspect} " filepath = cfgFilePath(filename) open(filepath, 'w') { |f| YAML.dump(cfg, f) } end |