123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::ConfigStore

Relationships & Source Files
Inherits: Object
Defined in: lib/rubocop/config_store.rb

Overview

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newConfigStore

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 10

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 = {}

  # By default the config is validated before it can be used.
  @validated = true
end

Instance Attribute Details

#options_config=(options_config) (writeonly)

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 28

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

#validated? (readonly)

Alias for #validated.

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 8

alias validated? validated

Instance Method Details

#for(file_or_dir)

If type (file/dir) is known beforehand, prefer using #for_file or #for_dir for improved performance

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 52

def for(file_or_dir)
  dir = if File.directory?(file_or_dir)
          file_or_dir
        else
          File.dirname(file_or_dir)
        end
  for_dir(dir)
end

#for_dir(dir)

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 61

def for_dir(dir)
  return @options_config if @options_config

  @path_cache[dir] ||= ConfigLoader.configuration_file_for(dir)
  path = @path_cache[dir]
  @object_cache[path] ||= begin
    print "For #{dir}: " if ConfigLoader.debug?
    ConfigLoader.configuration_from_file(path, check: validated?)
  end
end

#for_file(file)

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 42

def for_file(file)
  for_dir(File.dirname(file))
end

#for_pwd

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 46

def for_pwd
  for_dir(Dir.pwd)
end

#force_default_config!

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 33

def force_default_config!
  @options_config = ConfigLoader.default_configuration
end

#unvalidated

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 37

def unvalidated
  @validated = false
  self
end

#validated (readonly) Also known as: #validated?

[ GitHub ]

  
# File 'lib/rubocop/config_store.rb', line 7

attr_reader :validated