Class: LintTrappings::ConfigurationResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lint_trappings/configuration_resolver.rb

Overview

Resolves a configuration to its final representation.

This does the dirty work of loading and merging a configuration with the configurations it extends via the ‘extends` option or `linter_gems` option.

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ ConfigurationResolver

Returns a new instance of ConfigurationResolver.

Parameters:



10
11
12
# File 'lib/lint_trappings/configuration_resolver.rb', line 10

def initialize(loader)
  @loader = loader
end

Instance Method Details

#resolve(conf, options) ⇒ Object

Resolves the given configuration, returning a configuration with all external configuration files merged into one LintTrappings::Configuration.

Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lint_trappings/configuration_resolver.rb', line 18

def resolve(conf, options)
  configs_to_extend = Array(conf.delete('extends')).map do |extend_path|
    # If the path is relative, expand it relative to the path of this config
    config_path = File.expand_path(extend_path, conf.path)

    # Recursively resolve this configuration (it may have `extends` of its own)
    resolve(@loader.load_file(config_path))
  end

  # Load any configurations included by plugins
  require_paths = Array(conf.delete('linter_plugins')) + options.fetch(:linter_plugins, [])
  configs_to_extend += require_paths.map do |require_path|
    plugin = LinterPlugin.new(require_path)
    plugin.load
    resolve(@loader.load_file(plugin.config_file_path))
  end

  conf = extend_configs(configs_to_extend, conf) if configs_to_extend.any?
  conf
end