Module: CmdTools::Config
- Extended by:
- RubyPatch::AutoLoad
- Defined in:
- lib/cmd_tools/config.rb
Constant Summary collapse
- CONFIG_DIR =
File.join(ENV['HOME'], '.config/cmd_tools')
- CONFIG_FILE =
File.join(CONFIG_DIR, 'config.yaml')
- MACPORTS_EMACS =
'/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs'
- CONFIG_DEFAULT =
{ 'emacs' => if `uname`.chomp == "Darwin" && File.executable?(MACPORTS_EMACS) MACPORTS_EMACS else ENV['ALTERNATE_EDITOR'] || 'emacs' end, 'emacs_window_systems' => %w[x ns mac], }
Class Method Summary collapse
-
.load ⇒ Object
(Re)load config file.
Class Method Details
.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 |