Module: Hackmac::Config

Extended by:
ComplexConfig::Provider::Shortcuts, FileUtils
Defined in:
lib/hackmac/config.rb

Constant Summary collapse

DEFAULT =
File.read(File.join(File.dirname(__FILE__), 'hackmac.yml'))

Class Method Summary collapse

Class Method Details

.load(path: ENV.fetch('CONFIG_PATH', '~/.config/hackmac/hackmac.yml')) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/hackmac/config.rb', line 13

def self.load(path: ENV.fetch('CONFIG_PATH', '~/.config/hackmac/hackmac.yml'))
  path = Pathname.new(path).expand_path
  mkdir_p path.dirname
  ComplexConfig::Provider.config_dir = path.dirname
  unless path.exist?
    File.secure_write(path.to_s, DEFAULT)
  end
  puts "Loading config from #{path.to_s.inspect}."
  ComplexConfig::Provider[path.basename.to_s.sub(/\..*?\z/, '')]
end