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').freeze
CONFIG_FILE_NAME =
'.slim-lint.yml'

Class Method Summary collapse

Class Method Details

.default_configurationObject

Loads the built-in default configuration.



27
28
29
# File 'lib/slim_lint/configuration_loader.rb', line 27

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

.load_applicable_configObject

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



15
16
17
18
19
20
21
22
23
24
# 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) ⇒ SlimLint::Configuration

Loads a configuration, ensuring it extends the default configuration.

Parameters:

  • file (String)

Returns:



35
36
37
38
39
40
41
42
43
# 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) ⇒ SlimLint::Configuration

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

Parameters:

  • hash (Hash)

Returns:



50
51
52
53
54
# File 'lib/slim_lint/configuration_loader.rb', line 50

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

  default_configuration.merge(config)
end