Class: RuboCop::ConfigStore
- Inherits:
-
Object
- Object
- RuboCop::ConfigStore
- Defined in:
- lib/rubocop/config_store.rb
Overview
Handles caching of configurations and association of inspected ruby files to configurations.
Instance Attribute Summary collapse
-
#validated ⇒ Object
(also: #validated?)
readonly
Returns the value of attribute validated.
Instance Method Summary collapse
-
#for(file_or_dir) ⇒ Object
If type (file/dir) is known beforehand, prefer using #for_file or #for_dir for improved performance.
- #for_dir(dir) ⇒ Object
- #for_file(file) ⇒ Object
- #for_pwd ⇒ Object
- #force_default_config! ⇒ Object
-
#initialize ⇒ ConfigStore
constructor
A new instance of ConfigStore.
- #options_config=(options_config) ⇒ Object
- #unvalidated ⇒ Object
Constructor Details
#initialize ⇒ ConfigStore
Returns a new instance of ConfigStore.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 = 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
#validated ⇒ Object (readonly) Also known as: validated?
Returns the value of attribute validated.
7 8 9 |
# File 'lib/rubocop/config_store.rb', line 7 def validated @validated end |
Instance Method Details
#for(file_or_dir) ⇒ Object
If type (file/dir) is known beforehand, prefer using #for_file or #for_dir for improved performance
53 54 55 56 57 58 59 60 |
# File 'lib/rubocop/config_store.rb', line 53 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rubocop/config_store.rb', line 62 def for_dir(dir) return if @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) ⇒ Object
43 44 45 |
# File 'lib/rubocop/config_store.rb', line 43 def for_file(file) for_dir(File.dirname(file)) end |
#for_pwd ⇒ Object
47 48 49 |
# File 'lib/rubocop/config_store.rb', line 47 def for_pwd for_dir(Dir.pwd) end |
#force_default_config! ⇒ Object
34 35 36 |
# File 'lib/rubocop/config_store.rb', line 34 def force_default_config! = ConfigLoader.default_configuration end |
#options_config=(options_config) ⇒ Object
28 29 30 31 32 |
# File 'lib/rubocop/config_store.rb', line 28 def () loaded_config = ConfigLoader.load_file() = ConfigLoader.merge_with_default(loaded_config, ) end |
#unvalidated ⇒ Object
38 39 40 41 |
# File 'lib/rubocop/config_store.rb', line 38 def unvalidated @validated = false self end |