Class: LintTrappings::ConfigurationLoader
- Inherits:
-
Object
- Object
- LintTrappings::ConfigurationLoader
- Defined in:
- lib/lint_trappings/configuration_loader.rb
Overview
Manages configuration file loading.
Instance Method Summary collapse
-
#initialize(application) ⇒ ConfigurationLoader
constructor
A new instance of ConfigurationLoader.
-
#load(options = {}) ⇒ LintTrappings::Configuration
Load configuration file given the current working directory the application is running within.
-
#load_file(path) ⇒ LintTrappings::Configuration
Loads a configuration, ensuring it extends the base configuration.
Constructor Details
#initialize(application) ⇒ ConfigurationLoader
Returns a new instance of ConfigurationLoader.
7 8 9 |
# File 'lib/lint_trappings/configuration_loader.rb', line 7 def initialize(application) @application = application end |
Instance Method Details
#load(options = {}) ⇒ LintTrappings::Configuration
Load configuration file given the current working directory the application is running within.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lint_trappings/configuration_loader.rb', line 21 def load( = {}) config_file_names = @application.configuration_file_names working_directory = .fetch(:working_directory, Dir.pwd) directory = File.(working_directory) config_file = possible_config_files(config_file_names, directory).find(&:file?) if config_file load_file(config_file.to_path) else raise NoConfigurationFileError, "No configuration file #{config_file_names.join('/')} found in " \ 'working directory or any parent directory' end end |
#load_file(path) ⇒ LintTrappings::Configuration
Loads a configuration, ensuring it extends the base configuration.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lint_trappings/configuration_loader.rb', line 45 def load_file(path) load_from_file(path) rescue ::Psych::SyntaxError => error raise ConfigurationParseError, "Unable to parse configuration from '#{file}': #{error}", error.backtrace rescue Errno::ENOENT => error raise NoConfigurationFileError, "Unable to load configuration from '#{file}': #{error}" end |