Sha256: b05001a070d5e6be2114d6d2157c15979846e9bdfdc82853b36e7646b65a0acc

Contents?: true

Size: 713 Bytes

Versions: 6

Compression:

Stored size: 713 Bytes

Contents

require 'complex_config/shortcuts'
require 'tins/xt/secure_write'
require 'fileutils'
require 'pathname'

module Hackmac
  module Config
    extend FileUtils
    extend ComplexConfig::Provider::Shortcuts

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

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hackmac-1.4.1 lib/hackmac/config.rb
hackmac-1.4.0 lib/hackmac/config.rb
hackmac-1.3.0 lib/hackmac/config.rb
hackmac-1.2.1 lib/hackmac/config.rb
hackmac-1.2.0 lib/hackmac/config.rb
hackmac-1.1.3 lib/hackmac/config.rb