Class: Overcommit::ConfigurationLoader
- Inherits:
-
Object
- Object
- Overcommit::ConfigurationLoader
- Defined in:
- lib/overcommit/configuration_loader.rb
Overview
Manages configuration file loading.
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
File.join(OVERCOMMIT_HOME, 'config', 'default.yml')
- FILE_NAME =
'.overcommit.yml'
Class Method Summary collapse
- .default_configuration ⇒ Object
-
.load_file(file) ⇒ Object
Loads a configuration, ensuring it extends the default configuration.
- .load_from_file(file) ⇒ Object
- .load_repo_config ⇒ Object
Class Method Details
.default_configuration ⇒ Object
19 20 21 |
# File 'lib/overcommit/configuration_loader.rb', line 19 def self.default_configuration @default_config ||= load_from_file(DEFAULT_CONFIG_PATH) end |
.load_file(file) ⇒ Object
Loads a configuration, ensuring it extends the default configuration.
26 27 28 29 30 31 32 33 34 |
# File 'lib/overcommit/configuration_loader.rb', line 26 def self.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 |
.load_from_file(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/overcommit/configuration_loader.rb', line 36 def self.load_from_file(file) hash = if yaml = YAML.load_file(file) yaml.to_hash else {} end Overcommit::Configuration.new(hash) end |
.load_repo_config ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/overcommit/configuration_loader.rb', line 9 def self.load_repo_config overcommit_yml = File.join(Overcommit::Utils.repo_root, FILE_NAME) if File.exists?(overcommit_yml) load_file(overcommit_yml) else default_configuration end end |