Sha256: d5693f70b5eef0940e8df9fe1ded530d61a794f4672c83794307d2ddcf684e5d

Contents?: true

Size: 782 Bytes

Versions: 8

Compression:

Stored size: 782 Bytes

Contents

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

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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hackmac-1.8.0 lib/hackmac/config.rb
hackmac-1.7.1 lib/hackmac/config.rb
hackmac-1.7.0 lib/hackmac/config.rb
hackmac-1.6.1 lib/hackmac/config.rb
hackmac-1.6.0 lib/hackmac/config.rb
hackmac-1.5.1 lib/hackmac/config.rb
hackmac-1.5.0 lib/hackmac/config.rb
hackmac-1.4.2 lib/hackmac/config.rb