Class: SlimLint::ConfigurationLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/slim_lint/configuration_loader.rb

Overview

Manages configuration file loading.

Constant Summary collapse

DEFAULT_CONFIG_PATH =
File.join(SlimLint::HOME, 'config', 'default.yml')
CONFIG_FILE_NAME =
'.slim-lint.yml'

Class Method Summary collapse

Class Method Details

.default_configurationObject

Loads the built-in default configuration.



25
26
27
# File 'lib/slim_lint/configuration_loader.rb', line 25

def default_configuration
  @default_config ||= load_from_file(DEFAULT_CONFIG_PATH)
end

.load_applicable_configObject

Load configuration file given the current working directory the application is running within.



13
14
15
16
17
18
19
20
21
22
# File 'lib/slim_lint/configuration_loader.rb', line 13

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) ⇒ SlimLint::Configuration

Loads a configuration, ensuring it extends the default configuration.

Parameters:

  • file (String)

Returns:



33
34
35
36
37
38
39
40
41
# File 'lib/slim_lint/configuration_loader.rb', line 33

def load_file(file)
  config = load_from_file(file)

  default_configuration.merge(config)
rescue Psych::SyntaxError, Errno::ENOENT => error
  raise SlimLint::Exceptions::ConfigurationError,
        "Unable to load configuration from '#{file}': #{error}",
        error.backtrace
end

.load_hash(hash) ⇒ SlimLint::Configuration

Creates a configuration from the specified hash, ensuring it extends the default configuration.

Parameters:

  • hash (Hash)

Returns:



48
49
50
51
52
# File 'lib/slim_lint/configuration_loader.rb', line 48

def load_hash(hash)
  config = SlimLint::Configuration.new(hash)

  default_configuration.merge(config)
end