Class: RuboCop::FeatureLoader Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/feature_loader.rb |
Overview
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.
Class Method Summary
- .load(config_directory_path:, feature:) Internal use only
- .new(config_directory_path:, feature:) ⇒ FeatureLoader constructor Internal use only
Instance Attribute Summary
- #relative? ⇒ Boolean readonly private Internal use only
Instance Method Summary
- #load Internal use only
- #namespaced_feature ⇒ String private Internal use only
- #namespaced_target ⇒ String private Internal use only
- #relative(feature) ⇒ String readonly private Internal use only
- #seems_cannot_load_such_file_error?(error) ⇒ Boolean private Internal use only
- #target ⇒ String private Internal use only
Class Method Details
.load(config_directory_path:, 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
Instance Attribute Details
#relative? ⇒ Boolean
(readonly, private)
# File 'lib/rubocop/feature_loader.rb', line 75
def relative? @feature.start_with?('.') end
Instance Method Details
#load
[ GitHub ]# 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
#namespaced_feature ⇒ String (private)
# File 'lib/rubocop/feature_loader.rb', line 55
def namespaced_feature @feature.tr('-', '/') end
#namespaced_target ⇒ String (private)
# File 'lib/rubocop/feature_loader.rb', line 60
def namespaced_target if relative? relative(namespaced_feature) else namespaced_feature end end
#relative(feature) ⇒ String (readonly, private)
# File 'lib/rubocop/feature_loader.rb', line 70
def relative(feature) ::File.join(@config_directory_path, feature) end
#seems_cannot_load_such_file_error?(error) ⇒ Boolean
(private)
# File 'lib/rubocop/feature_loader.rb', line 81
def seems_cannot_load_such_file_error?(error) error.path == target end