Class: HamlLint::ConfigurationLoader
- Inherits:
-
Object
- Object
- HamlLint::ConfigurationLoader
- Defined in:
- lib/haml_lint/configuration_loader.rb
Overview
Manages configuration file loading.
Constant Summary collapse
- AUTO_GENERATED_FILE =
'.haml-lint_todo.yml'
- DEFAULT_CONFIG_PATH =
File.join(HamlLint::HOME, 'config', 'default.yml').freeze
- CONFIG_FILE_NAME =
'.haml-lint.yml'
Class Method Summary collapse
-
.default_configuration ⇒ Object
Loads the built-in default configuration.
-
.default_path_to_config ⇒ Object
Path to the default config file, if it exists.
-
.load_applicable_config(config_file = nil, options = {}) ⇒ HamlLint::Configuration
Load configuration file given the current working directory the application is running within.
-
.load_file(file, context = {}) ⇒ HamlLint::Configuration
Loads a configuration, ensuring it extends the default configuration.
-
.load_hash(hash) ⇒ HamlLint::Configuration
Creates a configuration from the specified hash, ensuring it extends the default configuration.
Class Method Details
.default_configuration ⇒ Object
Loads the built-in default configuration.
39 40 41 |
# File 'lib/haml_lint/configuration_loader.rb', line 39 def default_configuration @default_configuration ||= load_from_file(DEFAULT_CONFIG_PATH) end |
.default_path_to_config ⇒ Object
Path to the default config file, if it exists
32 33 34 35 36 |
# File 'lib/haml_lint/configuration_loader.rb', line 32 def default_path_to_config directory = File.(Dir.pwd) config_file = possible_config_files(directory).find(&:file?) config_file&.to_path end |
.load_applicable_config(config_file = nil, options = {}) ⇒ HamlLint::Configuration
Load configuration file given the current working directory the application is running within.
22 23 24 25 26 27 28 29 |
# File 'lib/haml_lint/configuration_loader.rb', line 22 def load_applicable_config(config_file = nil, = {}) config_file ||= default_path_to_config if config_file load_file(config_file, ) else default_configuration end end |
.load_file(file, context = {}) ⇒ HamlLint::Configuration
Loads a configuration, ensuring it extends the default configuration.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/haml_lint/configuration_loader.rb', line 52 def load_file(file, context = {}) # rubocop:disable Metrics context[:loaded_files] ||= [] context[:loaded_files].map! { |config_file| File.(config_file) } context[:exclude_files] ||= [] context[:exclude_files].map! { |config_file| File.(config_file) } config = load_from_file(File.(file)) configs = if context[:loaded_files].any? [resolve_inheritance(config, context), config] else [default_configuration, resolve_inheritance(config, context), config] end configs.reduce { |acc, elem| acc.merge(elem) } rescue Psych::SyntaxError, Errno::ENOENT => e raise HamlLint::Exceptions::ConfigurationError, "Unable to load configuration from '#{file}': #{e}", e.backtrace end |
.load_hash(hash) ⇒ HamlLint::Configuration
Creates a configuration from the specified hash, ensuring it extends the default configuration.
77 78 79 80 81 |
# File 'lib/haml_lint/configuration_loader.rb', line 77 def load_hash(hash) config = HamlLint::Configuration.new(hash) default_configuration.merge(config) end |