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.
38 39 40 |
# File 'lib/haml_lint/configuration_loader.rb', line 38 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
31 32 33 34 35 |
# File 'lib/haml_lint/configuration_loader.rb', line 31 def default_path_to_config directory = File.(Dir.pwd) config_file = possible_config_files(directory).find(&:file?) config_file ? config_file.to_path : nil end |
.load_applicable_config(config_file = nil, options = {}) ⇒ HamlLint::Configuration
Load configuration file given the current working directory the application is running within.
21 22 23 24 25 26 27 28 |
# File 'lib/haml_lint/configuration_loader.rb', line 21 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.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/haml_lint/configuration_loader.rb', line 51 def load_file(file, context = {}) context[:loaded_files] ||= [] context[:exclude_files] ||= [] config = load_from_file(file) [default_configuration, resolve_inheritance(config, context), config] .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.
69 70 71 72 73 |
# File 'lib/haml_lint/configuration_loader.rb', line 69 def load_hash(hash) config = HamlLint::Configuration.new(hash) default_configuration.merge(config) end |