Module: Hackmac::Config
- Extended by:
- ComplexConfig::Provider::Shortcuts, FileUtils, Term::ANSIColor
- Defined in:
- lib/hackmac/config.rb
Overview
A module that provides configuration loading and management functionality for Hackmac
The Config module handles the initialization and retrieval of Hackmac’s configuration settings from specified files or default locations. It manages configuration directories, creates default configuration files when needed, and loads configurations into memory for use throughout the application.
Constant Summary collapse
- DEFAULT =
File.read(File.join(File.dirname(__FILE__), 'hackmac.yml'))
Class Method Summary collapse
-
.load(path: ENV.fetch('HACKMAC_CONFIG', '~/.config/hackmac/hackmac.yml')) ⇒ ComplexConfig::Provider
Loads the Hackmac configuration from the specified path or default location.
Class Method Details
.load(path: ENV.fetch('HACKMAC_CONFIG', '~/.config/hackmac/hackmac.yml')) ⇒ ComplexConfig::Provider
Loads the Hackmac configuration from the specified path or default location
This method initializes the configuration system by reading from a specified file path or using the default configuration file location. It ensures the configuration directory exists, sets up the configuration provider’s directory, creates a default configuration file if one doesn’t exist, and loads the configuration into memory for use throughout the application.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hackmac/config.rb', line 47 def self.load(path: ENV.fetch('HACKMAC_CONFIG', '~/.config/hackmac/hackmac.yml')) path = Pathname.new(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 |