Class: RuboCop::ConfigFinder Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
FileFinder
|
|
Inherits: | Object |
Defined in: | lib/rubocop/config_finder.rb |
Overview
This class has methods related to finding configuration path.
Constant Summary
-
DEFAULT_FILE =
# File 'lib/rubocop/config_finder.rb', line 12File.join(RUBOCOP_HOME, 'config', 'default.yml')
-
DOTFILE =
# File 'lib/rubocop/config_finder.rb', line 9'.rubocop.yml'
-
RUBOCOP_HOME =
# File 'lib/rubocop/config_finder.rb', line 11File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
-
XDG_CONFIG =
# File 'lib/rubocop/config_finder.rb', line 10'config.yml'
Class Attribute Summary
-
.project_root
rw
Internal use only
Returns the path RuboCop inferred as the root of the project.
- .project_root=(value) rw Internal use only
Class Method Summary
- .find_config_path(target_dir) Internal use only
- .expand_path(path) private Internal use only
- .find_project_dotfile(target_dir) private Internal use only
- .find_project_root private Internal use only
- .find_project_root_dot_config private Internal use only
- .find_user_dotfile private Internal use only
- .find_user_xdg_config private Internal use only
FileFinder
- Extended
Class Attribute Details
.project_root (rw)
Returns the path RuboCop inferred as the root of the project. No file searches will go past this directory.
# File 'lib/rubocop/config_finder.rb', line 26
def project_root @project_root ||= find_project_root end
.project_root=(value) (rw)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 17
attr_writer :project_root
Class Method Details
.expand_path(path) (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 69
def (path) File. (path) rescue ArgumentError # Could happen because HOME or ID could not be determined. Fall back on # using the path literally in that case. path end
.find_config_path(target_dir)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 19
def find_config_path(target_dir) find_project_dotfile(target_dir) || find_project_root_dot_config || find_user_dotfile || find_user_xdg_config || DEFAULT_FILE end
.find_project_dotfile(target_dir) (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 40
def find_project_dotfile(target_dir) find_file_upwards(DOTFILE, target_dir, project_root) end
.find_project_root (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 32
def find_project_root pwd = Dir.pwd gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd) return unless gems_file File.dirname(gems_file) end
.find_project_root_dot_config (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 44
def find_project_root_dot_config return unless project_root dotfile = File.join(project_root, '.config', DOTFILE) return dotfile if File.exist?(dotfile) xdg_config = File.join(project_root, '.config', 'rubocop', XDG_CONFIG) xdg_config if File.exist?(xdg_config) end
.find_user_dotfile (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 54
def find_user_dotfile return unless ENV.key?('HOME') file = File.join(Dir.home, DOTFILE) file if File.exist?(file) end
.find_user_xdg_config (private)
[ GitHub ]# File 'lib/rubocop/config_finder.rb', line 62
def find_user_xdg_config xdg_config_home = (ENV.fetch('XDG_CONFIG_HOME', '~/.config')) xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG) xdg_config if File.exist?(xdg_config) end