ConfigMan/lib/configman/modules/utils.rb
VetheonGames 69b49d899a Major codebase refinement
Add deep_dup as a depend (it'll be removed in the next commit)
Make "EXPECTED_KEYS" a constant in the main module because every parser depends on access to the information through a common interface
Move sorting the hash into sections into a util module we can lazy load
Changed a bunch of things around to depend on the new files, classes, and modules
2023-10-14 00:12:28 -06:00

30 lines
656 B
Ruby

# frozen_string_literal: true
# config_util.rb
module ConfigMan
module Utils
def self.sort_into_sections(config_hash, expected_keys, loaded_modules)
sorted_config = Hash.new { |hash, key| hash[key] = {} }
config_hash.each do |key, value|
section_found = false
expected_keys.each do |section, keys|
next unless loaded_modules.include?(section)
next unless keys.include?(key)
sorted_config[section][key] = value
section_found = true
break
end
sorted_config['General'][key] = value unless section_found
end
sorted_config
end
end
end