Class: Lumin::Config::Loader
- Inherits:
-
Object
- Object
- Lumin::Config::Loader
- Defined in:
- lib/lumin/config/loader.rb
Instance Method Summary collapse
-
#initialize ⇒ Loader
constructor
A new instance of Loader.
- #load_file(path) ⇒ Object
Constructor Details
#initialize ⇒ Loader
Returns a new instance of Loader.
8 9 10 |
# File 'lib/lumin/config/loader.rb', line 8 def initialize @loading = [] end |
Instance Method Details
#load_file(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lumin/config/loader.rb', line 12 def load_file(path) = File.(path) if @loading.include?() raise ConfigError, "configuration inheritance cycle: #{}" end @loading << raw = YAML.safe_load_file(, permitted_classes: [], permitted_symbols: [], aliases: false) || {} raise ConfigError, "configuration root must be a mapping" unless raw.is_a?(Hash) raw = Config.stringify_keys(raw) inherited = Array(raw.delete("inherit_from")).reduce({}) do |merged, reference| Config.deep_merge(merged, load_file(resolve(reference, File.dirname()))) end Config.deep_merge(inherited, raw) rescue Psych::Exception => error raise ConfigError, "cannot load #{}: #{error.}" ensure @loading.delete() if end |