class SlimLint::ConfigurationLoader
Manages configuration file loading.
Constants
- CONFIG_FILE_NAME
- DEFAULT_CONFIG_PATH
Public Class Methods
default_configuration()
click to toggle source
Loads the built-in default configuration.
# File lib/slim_lint/configuration_loader.rb, line 27 def default_configuration @default_configuration ||= load_from_file(DEFAULT_CONFIG_PATH) end
load_applicable_config()
click to toggle source
Load configuration file given the current working directory the application is running within.
# File lib/slim_lint/configuration_loader.rb, line 15 def load_applicable_config directory = File.expand_path(Dir.pwd) config_file = possible_config_files(directory).find(&:file?) if config_file load_file(config_file.to_path) else default_configuration end end
load_file(file)
click to toggle source
Loads a configuration, ensuring it extends the default configuration.
@param file [String] @return [SlimLint::Configuration]
# File lib/slim_lint/configuration_loader.rb, line 35 def load_file(file) config = load_from_file(file) default_configuration.merge(config) rescue Psych::SyntaxError, Errno::ENOENT => e raise SlimLint::Exceptions::ConfigurationError, "Unable to load configuration from '#{file}': #{e}", e.backtrace end
load_hash(hash)
click to toggle source
Creates a configuration from the specified hash, ensuring it extends the default configuration.
@param hash [Hash] @return [SlimLint::Configuration]
# File lib/slim_lint/configuration_loader.rb, line 50 def load_hash(hash) config = SlimLint::Configuration.new(hash) default_configuration.merge(config) end
Private Class Methods
load_from_file(file)
click to toggle source
Parses and loads a configuration from the given file.
@param file [String] @return [SlimLint::Configuration]
# File lib/slim_lint/configuration_loader.rb, line 62 def load_from_file(file) hash = if yaml = YAML.load_file(file) yaml.to_hash else {} end SlimLint::Configuration.new(hash) end
possible_config_files(directory)
click to toggle source
Returns a list of possible configuration files given the context of the specified directory.
@param directory [String] @return [Array<Pathname>]
# File lib/slim_lint/configuration_loader.rb, line 78 def possible_config_files(directory) files = Pathname.new(directory) .enum_for(:ascend) .map { |path| path + CONFIG_FILE_NAME } files << Pathname.new(CONFIG_FILE_NAME) end