Method: CmdTools::Config.load
- Defined in:
- lib/cmd_tools/config.rb
.load ⇒ Object
(Re)load config file.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cmd_tools/config.rb', line 22 def self.load need_dump = false @config = if File.readable?(CONFIG_FILE) && File.size(CONFIG_FILE) > 0 config_from_file = YAML.load_file(CONFIG_FILE) config = CONFIG_DEFAULT.merge(config_from_file) need_dump = config_from_file.size != CONFIG_DEFAULT.size config else need_dump = true CONFIG_DEFAULT end if need_dump FileUtils.mkdir_p(CONFIG_DIR) open(CONFIG_FILE, 'w'){|io| io.write(@config.to_yaml) io.flush } end @config.each{|name, val| var = "@#{name}" instance_variable_set(var, val) eval <<-EOS def self.#{name} #{var} end EOS } self end |