class RuboCop::FeatureLoader
This class handles loading files (a.k.a. features in Ruby) specified by `–require` command line option and `require` directive in the config.
Normally, the given string is directly passed to `require`. If a string beginning with `.` is given, it is assumed to be relative to the given directory.
If a string containing `-` is given, it will be used as is, but if we cannot find the file to load, we will replace `-` with `/` and try it again as when Bundler loads gems.
@api private
Public Class Methods
load(config_directory_path:, feature:)
click to toggle source
@param [String] config_directory_path @param [String] feature
# File lib/rubocop/feature_loader.rb, line 20 def load(config_directory_path:, feature:) new(config_directory_path: config_directory_path, feature: feature).load end
new(config_directory_path:, feature:)
click to toggle source
@param [String] config_directory_path @param [String] feature
# File lib/rubocop/feature_loader.rb, line 27 def initialize(config_directory_path:, feature:) @config_directory_path = config_directory_path @feature = feature end
Public Instance Methods
load()
click to toggle source
# File lib/rubocop/feature_loader.rb, line 32 def load # Don't use `::Kernel.require(target)` to prevent the following error: # https://github.com/rubocop/rubocop/issues/10893 require(target) rescue ::LoadError => e raise if e.path != target begin # Don't use `::Kernel.require(target)` to prevent the following error: # https://github.com/rubocop/rubocop/issues/10893 require(namespaced_target) rescue ::LoadError => error_for_namespaced_target # NOTE: This wrap is necessary due to JRuby 9.3.4.0 incompatibility: # https://github.com/jruby/jruby/issues/7316 raise LoadError, e if error_for_namespaced_target.path == namespaced_target raise error_for_namespaced_target end end
Private Instance Methods
namespaced_feature()
click to toggle source
@return [String]
# File lib/rubocop/feature_loader.rb, line 55 def namespaced_feature @feature.tr('-', '/') end
namespaced_target()
click to toggle source
@return [String]
# File lib/rubocop/feature_loader.rb, line 60 def namespaced_target if relative? relative(namespaced_feature) else namespaced_feature end end
relative(feature)
click to toggle source
@param [String] @return [String]
# File lib/rubocop/feature_loader.rb, line 70 def relative(feature) ::File.join(@config_directory_path, feature) end
relative?()
click to toggle source
@return [Boolean]
# File lib/rubocop/feature_loader.rb, line 75 def relative? @feature.start_with?('.') end
seems_cannot_load_such_file_error?(error)
click to toggle source
@param [LoadError] error @return [Boolean]
# File lib/rubocop/feature_loader.rb, line 81 def seems_cannot_load_such_file_error?(error) error.path == target end
target()
click to toggle source
@return [String]
# File lib/rubocop/feature_loader.rb, line 86 def target if relative? relative(@feature) else @feature end end