lib/hackmac/config.rb in hackmac-0.8.3 vs lib/hackmac/config.rb in hackmac-1.0.0
- old
+ new
@@ -1,8 +1,9 @@
require 'complex_config/shortcuts'
require 'tins/xt/secure_write'
require 'fileutils'
+require 'pathname'
module Hackmac
module Config
extend FileUtils
extend ComplexConfig::Provider::Shortcuts
@@ -44,17 +45,17 @@
- BrcmFirmwareData
WhateverGreen:
github: 'acidanthera/WhateverGreen'
end
- def self.load
- path = File.expand_path('~/.config/hackmac')
- mkdir_p path
- ComplexConfig::Provider.config_dir = path
- config_path = File.join(path, 'hackmac.yml')
- unless File.exist?(config_path)
- File.secure_write(config_path, DEFAULT)
+ 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, DEFAULT)
end
- complex_config.hackmac
+ puts "Loading config from #{path.to_s.inspect}."
+ ComplexConfig::Provider[path.basename.to_s.sub(/\..*?\z/, '')]
end
end
end