Module: Hackmac::Config

Extended by:
ComplexConfig::Provider::Shortcuts, FileUtils, Term::ANSIColor
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('HACKMAC_CONFIG', '~/.config/hackmac/hackmac.yml')) ⇒ Object



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

def self.load(path: ENV.fetch('HACKMAC_CONFIG', '~/.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 #{color(33) { path.to_s.inspect} }."
  ComplexConfig::Provider[path.basename.to_s.sub(/\..*?\z/, '')]
end