Sha256: f391ea551dbf9772e4f72026ecce6b0a3985920f8805059fce54e21456f985b2
Contents?: true
Size: 1.18 KB
Versions: 9
Compression:
Stored size: 1.18 KB
Contents
require 'yaml' module Overcommit # Manages configuration file loading. class ConfigurationLoader DEFAULT_CONFIG_PATH = File.join(OVERCOMMIT_HOME, 'config', 'default.yml') FILE_NAME = '.overcommit.yml' class << self def load_repo_config overcommit_yml = File.join(Overcommit::Utils.repo_root, FILE_NAME) if File.exist?(overcommit_yml) load_file(overcommit_yml) else default_configuration end end def default_configuration @default_config ||= load_from_file(DEFAULT_CONFIG_PATH) end private # Loads a configuration, ensuring it extends the default configuration. def load_file(file) config = load_from_file(file) default_configuration.merge(config) rescue => error raise Overcommit::Exceptions::ConfigurationError, "Unable to load configuration from '#{file}': #{error}", error.backtrace end def load_from_file(file) hash = if yaml = YAML.load_file(file) yaml.to_hash else {} end Overcommit::Configuration.new(hash) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems