# frozen_string_literal: true require 'yaml' require 'fileutils' module ADN class Configurador CONFIG_PATH = File.join(__dir__, '..', 'config', 'config.yml') def self.leer return {} unless File.exist?(CONFIG_PATH) YAML.load_file(CONFIG_PATH) || {} rescue StandardError => e warn "Error leyendo configuración: #{e.message}" {} end def self.guardar(config) FileUtils.mkdir_p(File.dirname(CONFIG_PATH)) File.write(CONFIG_PATH, config.to_yaml) true rescue StandardError => e warn "Error guardando configuración: #{e.message}" false end def self.obtener(ruta_punto, default = nil) config = leer partes = ruta_punto.split('.') valor = config partes.each do |p| valor = valor[p] if valor.is_a?(Hash) return default if valor.nil? end valor end def self.establecer(ruta_punto, nuevo_valor) config = leer partes = ruta_punto.split('.') temp = config partes[0...-1].each do |p| temp[p] ||= {} temp = temp[p] end temp[partes.last] = nuevo_valor guardar(config) end end end