Class: Rubocop::ConfigStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/config_store.rb

Overview

Handles chaching of configurations and association of inspected ruby files to configurations.

Instance Method Summary collapse

Constructor Details

#initializeConfigStore

Returns a new instance of ConfigStore.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubocop/config_store.rb', line 7

def initialize
  # @options_config stores a config that is specified in the command line.
  # This takes precedence over configs located in any directories
  @options_config = nil

  # @path_cache maps directories to configuration paths. We search
  # for .rubocop.yml only if we haven't already found it for the
  # given directory.
  @path_cache = {}

  # @object_cache maps configuration file paths to
  # configuration objects so we only need to load them once.
  @object_cache = {}
end

Instance Method Details

#for(file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/config_store.rb', line 28

def for(file)
  return @options_config if @options_config

  dir = File.dirname(file)
  @path_cache[dir] ||= Config.configuration_file_for(dir)
  path = @path_cache[dir]
  @object_cache[path] ||= begin
                            print "For #{dir}: " if Config.debug?
                            Config.configuration_from_file(path)
                          end
end

#set_options_config(options_config) ⇒ Object



22
23
24
25
26
# File 'lib/rubocop/config_store.rb', line 22

def set_options_config(options_config)
  loaded_config = Config.load_file(options_config)
  @options_config = Config.merge_with_default(loaded_config,
                                              options_config)
end